Skip to content

Commit

Permalink
analyze interpreter line in Vala scripts (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince781 committed May 3, 2020
1 parent 4a60ced commit 68241b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/projects/defaultproject.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ class Vls.DefaultProject : Project {
Compilation btarget;
string uri = file.get_uri ();
string[] sources = {};
string[] args = {};
// glib-2.0.vapi and gobject-2.0.vapi are already added
if (!uri.has_suffix ("glib-2.0.vapi") && !uri.has_suffix ("gobject-2.0.vapi")) {
sources += uri;
}
// analyze interpeter line
if (content != null && (content.has_prefix ("#!") || content.has_prefix ("//"))) {
try {
args = Util.get_arguments_from_command_str (content.substring (2, content.index_of_char ('\n')));
debug ("parsed %d argument(s) from interpreter line ...", args.length);
for (int i = 0; i < args.length; i++)
debug ("[arg %d] %s", i, args[i]);
} catch (RegexError rerror) {
warning ("failed to parse interpreter line");
}
}
btarget = new Compilation (root_path, uri, uri, build_targets.size,
{"valac"}, {}, sources, {}, content != null ? new string[]{content} : null);
{"valac"}, args, sources, {}, content != null ? new string[]{content} : null);
// build it now so that information is available immediately on
// file open (other projects compile on LSP initialize(), so they don't
// need to do this)
Expand Down
2 changes: 1 addition & 1 deletion src/util.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Vls.Util {
MatchInfo match_info;
string[] args = {};

if (/(?(?<=')((\\\\|[^'\\\s]|\\')(\\\\|[^'\\]|\\')*(?='))|((?!')((?!\\ )(\\\\|\S)|\\ ))+)/.match (str, 0, out match_info)) {
if (/(?(?<=')((\\\\|[^'\\\s]|\\')(\\\\|[^'\\]|\\')*(?='))|((?!')((?!\\ )(\\\\|[^\s;])|\\ ))+)/.match (str, 0, out match_info)) {
while (match_info.matches ()) {
args += match_info.fetch (0);
match_info.next ();
Expand Down

0 comments on commit 68241b4

Please sign in to comment.