Skip to content

Commit

Permalink
Bug fixes: autoloaded variables, additional signature form, and a fix…
Browse files Browse the repository at this point in the history
… for var_continues
  • Loading branch information
bscan committed Oct 16, 2023
1 parent 61f6eaf commit 6c6c3ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions server/src/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function buildHoverDoc(symbol: string, elem: PerlElem, refined: PerlElem | undef
break;
case PerlSymbolKind.AutoLoadVar:
desc = `(autoloaded) ${symbol}`;
break;
default:
// We should never get here
desc = `Unknown: ${elem.name}`;
Expand Down
11 changes: 8 additions & 3 deletions server/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ function localVars(state: ParserState): boolean {
// line, or if this line starts with my or local
let match;
if (state.var_continues || (match = state.stmt.match(/^(?:my|our|local|state)\b/))) {
// The declaration continues if the line does not end with ;
state.var_continues = !state.stmt.endsWith(";") && !state.stmt.match(/[\)\=\}\{]/);
// The declaration continues unless there's a semicolon, signature end, or sub start.
// This can get tripped up with comments, but it's not a huge deal. subroutines are more important
state.var_continues = !state.stmt.match(/[\)\=\}\{;]/);

let mod_stmt = state.stmt;
// Remove my or local from statement, if present
mod_stmt = mod_stmt.replace(/^(my|our|local|state)\s+/, "");
Expand Down Expand Up @@ -242,7 +244,10 @@ function look_ahead_signatures(state: ParserState): string[] {
}
}
let match;
if ((match = stmt.match(/(?:^|{)\s*my\s+(\(\s*[\$@%]\w+\s*(?:,\s*[\$@%]\w+\s*)*\))\s*=\s*\@_/)) || (match = stmt.match(/(?:^|{)\s*my\s+(\s*[\$@%]\w+\s*)=\s*shift\b/))) {
if ((match = stmt.match(/(?:^|{)\s*my\s+(\(\s*[\$@%]\w+\s*(?:,\s*[\$@%]\w+\s*)*\))\s*=\s*\@_/)) || // my ($foo, $bar) = @_
(match = stmt.match(/(?:^|{)\s*my\s+(\s*[\$@%]\w+\s*)=\s*shift\b/)) || // my $foo = shift
(match = stmt.match(/(?:^|{)\s*my\s*(\(\s*[\$@%]\w+\s*\))\s*=\s*shift\b/)) // my ($foo) = shift
) {
let vars = match[1].matchAll(/([\$\@\%][\w:]+)\b/g);
for (const matchvar of vars) {
sig_vars.push(matchvar[0]);
Expand Down

0 comments on commit 6c6c3ce

Please sign in to comment.