Skip to content

Commit

Permalink
Local variables are now properly suggested. Should solve #36.
Browse files Browse the repository at this point in the history
  • Loading branch information
SkaceKamen committed Oct 25, 2018
1 parent 6d97c2b commit ef7ce63
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ export interface SQFLintSettings {
* List of variables local to document.
*/
interface DocumentVariables {
[ uri: string ] : { [name: string]: DocumentVariable };
[ uri: string ] : DocumentVariablesList;
}

interface DocumentVariablesList { [name: string]: DocumentVariable }
/**
* Variable local to document. Contains locations local to document.
*/
Expand Down Expand Up @@ -1155,6 +1156,14 @@ export class SQFLintServer {
}
}

let local = this.findLocalVariables(params.textDocument, hover)
local.forEach(local => {
items.push({
label: local.name,
kind: CompletionItemKind.Variable
});
})

for (let ident in this.globalVariables) {
let variable = this.globalVariables[ident];

Expand Down Expand Up @@ -1287,6 +1296,18 @@ export class SQFLintServer {
typeof(ns[name]) !== "undefined";
}

/**
* Finds local variables matching part specified query.
*/
private findLocalVariables(document: TextDocumentIdentifier, query: string): DocumentVariable[] {
let ns: DocumentVariablesList;
if (typeof(ns = this.documentVariables[document.uri]) === "undefined")
return null;
return Object.keys(ns)
.filter(name => name.toLocaleLowerCase().indexOf(query.toLowerCase()) >= 0)
.map(name => ns[name])
}

/**
* Returns local variable info or null/undefined;
*/
Expand Down

0 comments on commit ef7ce63

Please sign in to comment.