Skip to content

Commit aabddde

Browse files
committed
make GIR documentation engine use custom targets
- Make GIR documentation work with generated GIRs by allowing projects to specify additional dirs to look for GIRs in. This is especially useful with Meson subprojects. - Enable GIR documentation by default now. The feature is stable.
1 parent 3eea249 commit aabddde

File tree

6 files changed

+43
-50
lines changed

6 files changed

+43
-50
lines changed

meson_options.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
option('parse_system_girs', type: 'boolean', value: true, description: 'Parse system GIRs for symbol documentation')
21
option('active_parameter', type: 'boolean', value: false, description: 'Support activeParameter in signatureHelp')
32
option('debug_mem', type: 'boolean', value: false, description: 'Debug memory usage')
43
option('builder_abi', type: 'string', value: 'auto', description: 'Builder ABI version. Use a value like \'3.38\'')

src/documentation/doccomment.vala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class Vls.DocComment {
4848
body = markdown_doc;
4949
}
5050

51-
#if PARSE_SYSTEM_GIRS
5251
/**
5352
* Render a GTK-Doc-formatted comment into Markdown.
5453
*
@@ -68,7 +67,6 @@ class Vls.DocComment {
6867
return_body = documentation.render_gtk_doc_comment (gir_comment.return_content, compilation);
6968
}
7069
}
71-
#endif
7270

7371
/**
7472
* Render a ValaDoc-formatted comment into Markdown.

src/documentation/girdocumentation.vala

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ class Vls.GirDocumentation {
4343
if (girpath != null) {
4444
context.add_source_file (new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, girpath));
4545
added[gir_package] = vapi_package;
46+
debug ("adding GIR %s for package %s", gir_package, vapi_package);
4647
}
4748
}
4849

4950
/**
5051
* Create a new holder for GIR docs by adding all GIRs found in
51-
* `/usr/share/gir-1.0` and `/usr/local/share/gir-1.0`
52+
* `/usr/share/gir-1.0` and `/usr/local/share/gir-1.0`, as well as
53+
* additional directories in `custom_gir_dirs`.
54+
*
55+
* @param vala_packages set of VAPIs to find matching GIRs for
56+
* @param custom_gir_dirs set of directories to search for additional GIRs in
5257
*/
53-
public GirDocumentation (Gee.Collection<Vala.SourceFile> packages) {
58+
public GirDocumentation (Gee.Collection<Vala.SourceFile> vala_packages,
59+
Gee.Collection<File> custom_gir_dirs) {
5460
context = new Vala.CodeContext ();
5561
context.report = new Sink ();
5662
Vala.CodeContext.push (context);
@@ -61,41 +67,23 @@ class Vls.GirDocumentation {
6167
context.add_define ("GOBJECT");
6268
#endif
6369

70+
// add additional dirs
71+
string[] gir_directories = context.gir_directories;
72+
foreach (var additional_gir_dir in custom_gir_dirs)
73+
gir_directories += additional_gir_dir.get_path ();
74+
context.gir_directories = gir_directories;
75+
6476
// add packages
6577
add_gir ("GLib-2.0", "glib-2.0");
6678
add_gir ("GObject-2.0", "gobject-2.0");
6779

68-
foreach (string data_dir in Environment.get_system_data_dirs ()) {
69-
File dir = File.new_for_path (Path.build_filename (data_dir, "gir-1.0"));
70-
if (!dir.query_exists ())
71-
continue;
72-
try {
73-
var enumerator = dir.enumerate_children (
74-
"standard::*",
75-
FileQueryInfoFlags.NONE);
76-
FileInfo? file_info;
77-
while ((file_info = enumerator.next_file ()) != null) {
78-
if ((file_info.get_file_type () != FileType.REGULAR &&
79-
file_info.get_file_type () != FileType.SYMBOLIC_LINK) ||
80-
file_info.get_is_backup () || file_info.get_is_hidden () ||
81-
!file_info.get_name ().has_suffix (".gir"))
82-
continue;
83-
string gir_pkg = Path.get_basename (file_info.get_name ());
84-
gir_pkg = gir_pkg.substring (0, gir_pkg.length - ".gir".length);
85-
Vala.SourceFile? vapi_pkg_match = packages.first_match (
86-
pkg => pkg.gir_version != null && @"$(pkg.gir_namespace)-$(pkg.gir_version)" == gir_pkg);
87-
if (!added.has_key (gir_pkg) && vapi_pkg_match != null) {
88-
debug (@"adding GIR $gir_pkg for package $(vapi_pkg_match.package_name)");
89-
add_gir (gir_pkg, vapi_pkg_match.package_name);
90-
}
91-
}
92-
} catch (Error e) {
93-
debug (@"could not enumerate $(dir.get_uri ()): $(e.message)");
94-
}
80+
foreach (var vapi_pkg in vala_packages) {
81+
if (vapi_pkg.gir_namespace != null && vapi_pkg.gir_version != null)
82+
add_gir (@"$(vapi_pkg.gir_namespace)-$(vapi_pkg.gir_version)", vapi_pkg.package_name);
9583
}
9684

9785
string missed = "";
98-
packages.filter (pkg => !added.keys.any_match (pkg_name => pkg.gir_version != null && pkg_name == @"$(pkg.gir_namespace)-$(pkg.gir_version)"))
86+
vala_packages.filter (pkg => !added.keys.any_match (pkg_name => pkg.gir_version != null && pkg_name == @"$(pkg.gir_namespace)-$(pkg.gir_version)"))
9987
.foreach (vapi_pkg => {
10088
if (missed.length > 0)
10189
missed += ", ";

src/meson.build

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ vls_src = files([
1010
'codehelp/symbolvisitor.vala',
1111
'documentation/cnamemapper.vala',
1212
'documentation/doccomment.vala',
13+
'documentation/girdocumentation.vala',
1314
'projects/buildtarget.vala',
1415
'projects/buildtask.vala',
1516
'projects/ccproject.vala',
@@ -25,11 +26,6 @@ vls_src = files([
2526
'servertypes.vala',
2627
])
2728

28-
if get_option('parse_system_girs')
29-
vls_src += 'documentation/girdocumentation.vala'
30-
add_project_arguments(['--define=PARSE_SYSTEM_GIRS'], language: 'vala')
31-
endif
32-
3329
if get_option('active_parameter')
3430
add_project_arguments(['--define=VALA_FEATURE_INITIAL_ARGUMENT_COUNT'], language: 'vala')
3531
endif

src/projects/project.vala

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ abstract class Vls.Project : Object {
337337
return modified;
338338
}
339339

340-
#if PARSE_SYSTEM_GIRS
341340
/**
342341
* Get all unique packages used in this project
343342
*/
@@ -353,7 +352,24 @@ abstract class Vls.Project : Object {
353352
}
354353
return results;
355354
}
356-
#endif
355+
356+
/**
357+
* Gets a list of all directories containing GIRs that are generated by a
358+
* target.
359+
*/
360+
public Collection<File> get_custom_gir_dirs () {
361+
var results = new HashSet<File> (Util.file_hash, Util.file_equal);
362+
foreach (var btarget in build_targets) {
363+
foreach (var output_file in btarget.output) {
364+
if (output_file.get_path ().has_suffix (".gir")) {
365+
var parent = output_file.get_parent ();
366+
if (parent != null)
367+
results.add (parent);
368+
}
369+
}
370+
}
371+
return results;
372+
}
357373

358374
/**
359375
* Get all source files used in this project.

src/server.vala

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ class Vls.Server : Object {
3434
const int64 update_context_delay_max_us = 1000 * 1000;
3535
const uint wait_for_context_update_delay_ms = 200;
3636

37-
#if PARSE_SYSTEM_GIRS
3837
/**
3938
* Contains documentation from found GIR files.
4039
*/
4140
GirDocumentation documentation;
42-
#endif
41+
4342
HashSet<Request> pending_requests;
4443

4544
bool shutting_down = false;
@@ -329,13 +328,14 @@ class Vls.Server : Object {
329328
}
330329
}
331330

332-
#if PARSE_SYSTEM_GIRS
333331
// create documentation (compiles GIR files too)
334332
var packages = new HashSet<Vala.SourceFile> ();
335-
foreach (var project in new_projects)
333+
var custom_gir_dirs = new HashSet<File> (Util.file_hash, Util.file_equal);
334+
foreach (var project in new_projects) {
336335
packages.add_all (project.get_packages ());
337-
documentation = new GirDocumentation (packages);
338-
#endif
336+
custom_gir_dirs.add_all (project.get_custom_gir_dirs ());
337+
}
338+
documentation = new GirDocumentation (packages, custom_gir_dirs);
339339

340340
// build and publish diagnostics
341341
foreach (var project in new_projects) {
@@ -1004,21 +1004,17 @@ class Vls.Server : Object {
10041004

10051005
Vala.Comment? comment = null;
10061006
DocComment? doc_comment = null;
1007-
#if PARSE_SYSTEM_GIRS
10081007
var gir_sym = documentation.find_gir_symbol (sym);
10091008
if (gir_sym != null && gir_sym.comment != null)
10101009
comment = gir_sym.comment;
10111010
else
1012-
#endif
10131011
comment = sym.comment;
10141012

10151013
if (comment != null) {
10161014
try {
1017-
#if PARSE_SYSTEM_GIRS
10181015
if (comment is Vala.GirComment || gir_sym != null && gir_sym.comment == comment)
10191016
doc_comment = new DocComment.from_gir_comment (comment, documentation, compilation);
10201017
else
1021-
#endif
10221018
doc_comment = new DocComment.from_valadoc_comment (comment, sym, compilation);
10231019
} catch (RegexError e) {
10241020
warning ("failed to render comment - %s", e.message);

0 commit comments

Comments
 (0)