Skip to content

Commit

Permalink
pull-pylance-with-pyright-1.1.299 (#4797)
Browse files Browse the repository at this point in the history
Co-authored-by: Bill Schnurr <[email protected]>
Co-authored-by: HeeJae Chang <[email protected]>
Co-authored-by: Erik De Bonte <[email protected]>
Co-authored-by: Rich Chiodo <[email protected]>
  • Loading branch information
5 people authored Mar 17, 2023
1 parent cb9952a commit 68a8e98
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class BackgroundAnalysisProgram {
return this._backgroundAnalysis;
}

contains(filePath: string): boolean {
hasSourceFile(filePath: string): boolean {
return !!this._program.getSourceFile(filePath);
}

Expand Down
5 changes: 2 additions & 3 deletions packages/pyright-internal/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export class AnalyzerService {
private _backgroundAnalysisProgram: BackgroundAnalysisProgram;
private _backgroundAnalysisCancellationSource: AbstractCancellationTokenSource | undefined;
private _disposed = false;

private _pendingLibraryChanges: RefreshOptions = { changesOnly: true };

constructor(instanceName: string, fs: FileSystem, options: AnalyzerServiceOptions) {
Expand Down Expand Up @@ -285,8 +284,8 @@ export class AnalyzerService {
this._applyConfigOptions(host);
}

contains(filePath: string): boolean {
return this.backgroundAnalysisProgram.contains(filePath);
hasSourceFile(filePath: string): boolean {
return this.backgroundAnalysisProgram.hasSourceFile(filePath);
}

isTracked(filePath: string): boolean {
Expand Down
30 changes: 19 additions & 11 deletions packages/pyright-internal/src/languageServerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
return this._workspaceFactory.getWorkspaceForFile(filePath, pythonPath);
}

async getContainingWorkspacesForFile(filePath: string): Promise<Workspace[]> {
return this._workspaceFactory.getContainingWorkspacesForFile(filePath);
}

reanalyze() {
this._workspaceFactory.items().forEach((workspace) => {
workspace.service.invalidateAndForceReanalysis();
Expand Down Expand Up @@ -1276,8 +1280,11 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
return;
}

const workspace = await this.getWorkspaceForFile(filePath);
workspace.service.setFileOpened(filePath, params.textDocument.version, params.textDocument.text, ipythonMode);
// Send this open to all the workspaces that might contain this file.
const workspaces = await this.getContainingWorkspacesForFile(filePath);
workspaces.forEach((w) => {
w.service.setFileOpened(filePath, params.textDocument.version, params.textDocument.text, ipythonMode);
});
}

protected async onDidChangeTextDocument(params: DidChangeTextDocumentParams, ipythonMode = IPythonMode.None) {
Expand All @@ -1289,13 +1296,11 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
return;
}

const workspace = await this.getWorkspaceForFile(filePath);
workspace.service.updateOpenFileContents(
filePath,
params.textDocument.version,
params.contentChanges,
ipythonMode
);
// Send this change to all the workspaces that might contain this file.
const workspaces = await this.getContainingWorkspacesForFile(filePath);
workspaces.forEach((w) => {
w.service.updateOpenFileContents(filePath, params.textDocument.version, params.contentChanges, ipythonMode);
});
}

protected async onDidCloseTextDocument(params: DidCloseTextDocumentParams) {
Expand All @@ -1305,8 +1310,11 @@ export abstract class LanguageServerBase implements LanguageServerInterface {
return;
}

const workspace = await this.getWorkspaceForFile(filePath);
workspace.service.setFileClosed(filePath);
// Send this close to all the workspaces that might contain this file.
const workspaces = await this.getContainingWorkspacesForFile(filePath);
workspaces.forEach((w) => {
w.service.setFileClosed(filePath);
});
}

protected onDidChangeWatchedFiles(params: DidChangeWatchedFilesParams) {
Expand Down
Loading

0 comments on commit 68a8e98

Please sign in to comment.