Skip to content

Commit

Permalink
add --version flag (#210)
Browse files Browse the repository at this point in the history
This helps with Brew packaging.

Closes #210
  • Loading branch information
Prince781 committed Jul 9, 2021
1 parent cb85813 commit 3e01b83
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
5 changes: 3 additions & 2 deletions config.vala.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Config {
const string libvala_version = "@LIBVALA_VERSION@";
const string version = "@VLS_VERSION@";
const string LIBVALA_VERSION = "@LIBVALA_VERSION@";
const string PROJECT_BUGSITE = "@PROJECT_BUGSITE@";
const string PROJECT_NAME = "@PROJECT_NAME@";
}
7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ endif

conf = configuration_data()
conf.set('LIBVALA_VERSION', libvala.version())
conf.set('VLS_VERSION', meson.project_version())
conf.set('PROJECT_BUGSITE', 'https://github.com/Prince781/vala-language-server/issues')
conf.set('PROJECT_NAME', meson.project_name())

conf_file = configure_file(input: 'config.vala.in',
output: 'config.vala',
configuration: conf)

version_file = vcs_tag(input: 'version.vala.in',
output: 'version.vala',
command: ['git', 'describe', '--tags', '--dirty'])

add_project_arguments(['--enable-gobject-tracing', '--fatal-warnings'], language: 'vala')

extra_vala_sources = files([
Expand Down
2 changes: 1 addition & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ endif

executable('vala-language-server',
dependencies: deps,
sources: [vls_src, conf_file, extra_vala_sources],
sources: [vls_src, conf_file, version_file, extra_vala_sources],
c_args: ['-DG_LOG_DOMAIN="vls"'],
install: true)
33 changes: 31 additions & 2 deletions src/server.vala
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Vls.Server : Object {
),
serverInfo: buildDict (
name: new Variant.string ("Vala Language Server"),
version: new Variant.string (Config.version)
version: new Variant.string (Config.PROJECT_VERSION)
)
), cancellable);
} catch (Error e) {
Expand Down Expand Up @@ -1968,9 +1968,38 @@ class Vls.Server : Object {
}
}

void main () {
/**
* `--version`
*/
bool opt_version;

const OptionEntry[] entries = {
{ "version", 'V', OptionFlags.NONE, OptionArg.NONE, ref opt_version, "Print the version and commit info", null },
{}
};

int main (string[] args) {
Environment.set_prgname ("vala-language-server");
var ocontext = new OptionContext ("- vala-language-server");
ocontext.add_main_entries (entries, null);
ocontext.set_summary ("A language server for Vala");
ocontext.set_description (@"Report bugs to $(Config.PROJECT_BUGSITE)");
try {
ocontext.parse (ref args);
} catch (Error e) {
stderr.printf ("%s\n", e.message);
stderr.printf ("Run '%s --version' to print version, or no arguments to run the language server.\n", args[0]);
return 1;
}

if (opt_version) {
stdout.printf ("%s %s\n", Config.PROJECT_NAME, Config.PROJECT_VERSION);
return 1;
}

// otherwise
var loop = new MainLoop ();
new Vls.Server (loop);
loop.run ();
return 0;
}
3 changes: 3 additions & 0 deletions version.vala.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Config {
const string PROJECT_VERSION = "@VCS_TAG@";
}

0 comments on commit 3e01b83

Please sign in to comment.