Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meson: support settings overrides from editor #306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/projects/mesonproject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Vls.MesonProject : Project {
private string build_dir;
private bool configured_once;
private bool requires_general_build;
private string[] extra_setup_args = {};
private string[] extra_compile_args = {};

/**
* Substitute special arguments like `@INPUT@` and `@OUTPUT@` as they
Expand Down Expand Up @@ -209,6 +211,9 @@ class Vls.MesonProject : Project {
string proc_stdout, proc_stderr;
int proc_status;

foreach (string arg in extra_setup_args)
spawn_args += arg;

string command_str = "";
foreach (string part in spawn_args) {
if (command_str != "")
Expand Down Expand Up @@ -761,9 +766,13 @@ class Vls.MesonProject : Project {
if (requires_general_build) {
int proc_status;
string proc_stdout, proc_stderr;
string[] spawn_args = {"meson", "compile"};

foreach (string arg in extra_compile_args)
spawn_args += arg;

Process.spawn_sync (build_dir,
{"meson", "compile"},
spawn_args,
null,
SpawnFlags.SEARCH_PATH,
null,
Expand All @@ -781,9 +790,28 @@ class Vls.MesonProject : Project {
base.build_if_stale (cancellable);
}

public MesonProject (string root_path, FileCache file_cache, Cancellable? cancellable = null) throws Error {
public MesonProject (string root_path, FileCache file_cache,
Lsp.EditorOptions? editor_options,
Cancellable? cancellable = null) throws Error {
base (root_path, file_cache);
this.build_dir = DirUtils.make_tmp (@"vls-meson-$(str_hash (root_path))-XXXXXX");
var default_build_dir_template = @"vls-meson-$(str_hash (root_path))-XXXXXX";
if (editor_options != null) {
debug ("overriding with VSCode Meson plugin settings: %s",
Json.gobject_to_data (editor_options, null));
this.extra_setup_args = editor_options.mesonConfigureOptions;
this.extra_compile_args = editor_options.mesonCompileOptions;
if (editor_options.mesonBuildDir != null) {
var meson_build_dir = File.new_for_path (editor_options.mesonBuildDir);
try {
meson_build_dir.make_directory_with_parents (cancellable);
this.build_dir = editor_options.mesonBuildDir;
} catch (IOError.EXISTS e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cancellable error isnt handled here I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is intentional. In the case of cancellation, we want to back out of configuring the Meson build entirely.

// ignore whether the build folder exists
}
}
}
if (this.build_dir == null)
this.build_dir = DirUtils.make_tmp (default_build_dir_template);
reconfigure_if_stale (cancellable);
}

Expand Down
27 changes: 27 additions & 0 deletions src/protocol.vala
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,38 @@ namespace Lsp {
public TextDocumentClientCapabilities textDocument { get; set; default = new TextDocumentClientCapabilities (); }
}

/**
* (Custom) Editor type for {@link EditorOptions}
*/
enum EditorType {
UNKNOWN = 0,
VSCODE = 1
}

/**
* (Custom) extra settings and capabilities of the editor.
* These may be overrides for projects. This is not LSP-specific.
*/
class EditorOptions : Object {
public EditorType editorType { get; set; }
public string[] mesonConfigureOptions { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe arrays arent "native" gobject properties, so they probably cannot be serialized automatically. I guess you need to implement the Json.Serializable interface.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the exception is string[] which becomes gchararray in the GLib type system.

public string[] mesonCompileOptions { get; set; }
private string? _mesonBuildDir;
public string? mesonBuildDir {
get { return _mesonBuildDir; }
set {
if (value != null && value.length > 0)
_mesonBuildDir = value;
}
}
}

class InitializeParams : Object {
public int processId { get; set; }
public string? rootPath { get; set; }
public string? rootUri { get; set; }
public ClientCapabilities capabilities { get; set; default = new ClientCapabilities (); }
public EditorOptions? initializationOptions { get; set; }
}

class SignatureInformation : Object, Json.Serializable {
Expand Down
10 changes: 6 additions & 4 deletions src/server.vala
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,13 @@ class Vls.Server : Jsonrpc.Server {
// TODO: autotools, make(?), cmake(?)
if (meson_file.query_exists (cancellable)) {
try {
backend_project = new MesonProject (root_path, file_cache, cancellable);
backend_project = new MesonProject (root_path, file_cache,
init_params.initializationOptions, cancellable);
} catch (ProjectError.VERSION_UNSUPPORTED e) {
// ignore and skip to the next project
show_message (client, @"Won't use Meson project - $(e.message)", MessageType.Warning);
} catch (Error e) {
if (!(e is ProjectError.VERSION_UNSUPPORTED)) {
show_message (client, @"Failed to initialize Meson project - $(e.message)", MessageType.Error);
}
show_message (client, @"Failed to initialize Meson project - $(e.message)", MessageType.Error);
}
}

Expand Down
Loading