Skip to content

Commit c5fbb36

Browse files
authored
Dbaeumer/fun-marmot-blue (#297)
* WIP * Make TypeOfLocalsRunnable work in more cases.
1 parent 49e3a8d commit c5fbb36

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/extension/typescriptContext/serverPlugin/src/common/baseContextProviders.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ export class TypeOfLocalsRunnable extends AbstractContextRunnable {
194194
return;
195195
}
196196
const sourceFile = token.getSourceFile();
197+
// When we try to capture locals outside of a callable (e.g. top level in a source file) we capture the declarations as
198+
// scope. If we are inside the body of the callable defines the scope.
197199
let variableDeclarations: Set<tt.VariableDeclarationList> | undefined = this.cacheScope === undefined ? new Set() : undefined;
198200
// The symbols are block scope variables. We try to find the type of the variable
199201
// to include it in the context.
@@ -202,12 +204,6 @@ export class TypeOfLocalsRunnable extends AbstractContextRunnable {
202204
if (this.excludes.has(symbol)) {
203205
continue;
204206
}
205-
const symbolSourceFile = Symbols.getPrimarySourceFile(symbol);
206-
// If the symbol is not defined in the current source file we skip it. It would otherwise
207-
// pollute with too many types from the global scope from other files.
208-
if (symbolSourceFile !== sourceFile || this.skipSourceFile(symbolSourceFile)) {
209-
continue;
210-
}
211207
const declaration: tt.VariableDeclaration | undefined = Symbols.getDeclaration(symbol, ts.SyntaxKind.VariableDeclaration);
212208
if (declaration === undefined) {
213209
continue;

src/extension/typescriptContext/vscode-node/languageContextService.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -807,19 +807,17 @@ class RunnableResultManager implements vscode.Disposable {
807807
items.set(key, item);
808808
}
809809
};
810-
// Clear all within runnable results that don't contain the requested position.
811-
for (let i = 0; i < this.withInRangeRunnableResults.length;) {
812-
const entry = this.withInRangeRunnableResults[i];
813-
if (entry.range.contains(position)) {
814-
i++;
815-
continue;
816-
}
817-
const id = entry.resultId;
818-
this.results.delete(id);
819-
this.withInRangeRunnableResults.splice(i, 1);
820-
}
821810
for (const [id, item] of this.results.entries()) {
822-
handleRunnableResult(id, item);
811+
const scope = item.cache?.scope;
812+
if (scope === undefined || scope.kind !== protocol.CacheScopeKind.WithinRange) {
813+
handleRunnableResult(id, item);
814+
} else {
815+
const r = scope.range;
816+
const range = new vscode.Range(r.start.line, r.start.character, r.end.line, r.end.character);
817+
if (range.contains(position)) {
818+
handleRunnableResult(id, item);
819+
}
820+
}
823821
}
824822
}
825823
return { client, clientOnTimeout, server, itemMap: items, resultMap: new Map(this.results) };

0 commit comments

Comments
 (0)