From a2f7ace943b017fe0a265184d89f62e44c3a800c Mon Sep 17 00:00:00 2001 From: detachhead Date: Sat, 2 Nov 2024 14:49:19 +1000 Subject: [PATCH 1/3] fix docstring for `RenameUsageFinder`, i dont think module-level docstrings are a thing in js/ts --- .../pyright-internal/src/analyzer/renameUsageFinder.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/pyright-internal/src/analyzer/renameUsageFinder.ts b/packages/pyright-internal/src/analyzer/renameUsageFinder.ts index c78244c5ff..3aaa16eafa 100644 --- a/packages/pyright-internal/src/analyzer/renameUsageFinder.ts +++ b/packages/pyright-internal/src/analyzer/renameUsageFinder.ts @@ -1,7 +1,3 @@ -/** - * visitor that looks for imports of an old file path and creates {@link TextEdit}s to update them for the new file path - */ - import { TextEdit } from 'vscode-languageserver-types'; import { ModuleNameNode, NameNode, ParseNodeType } from '../parser/parseNodes'; import { ParseTreeWalker } from './parseTreeWalker'; @@ -14,6 +10,9 @@ import { TextRange } from '../common/textRange'; import { ModuleType, TypeCategory } from './types'; import { Program } from './program'; +/** + * visitor that looks for imports of an old file path and creates {@link TextEdit}s to update them for the new file path + */ export class RenameUsageFinder extends ParseTreeWalker { edits: TextEdit[] = []; private _oldModuleName: string; From 5648578a91111436d14fbc593b6e16ef7cd4aa4e Mon Sep 17 00:00:00 2001 From: detachhead Date: Sat, 2 Nov 2024 14:52:16 +1000 Subject: [PATCH 2/3] don't do the rename files check for files that aren't in the workspace, such as non-python files --- packages/pyright-internal/src/languageServerBase.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/pyright-internal/src/languageServerBase.ts b/packages/pyright-internal/src/languageServerBase.ts index 0fec7a0ac4..36e3530549 100644 --- a/packages/pyright-internal/src/languageServerBase.ts +++ b/packages/pyright-internal/src/languageServerBase.ts @@ -1156,9 +1156,16 @@ export abstract class LanguageServerBase implements LanguageServerInterface, Dis } const workspace = await this.getWorkspaceForFile(newUri); const program = workspace.service.backgroundAnalysisProgram.program; + + // if the uri being renamed is not part of the workspace, don't bother + if (!program.containsSourceFileIn(oldUri)) { + continue; + } + + const oldFileContents = program.getParseResults(oldUri); workspace.service.getUserFiles().forEach((file) => { const currentFileParseResults = program.getParseResults(file); - const oldFile = program.getParseResults(oldUri) ?? oldUri; + const oldFile = oldFileContents ?? oldUri; if (currentFileParseResults && workspace.rootUri && program.evaluator) { const importFinder = new RenameUsageFinder(program, currentFileParseResults, oldFile, newUri); importFinder.walk(currentFileParseResults.parserOutput.parseTree); From 3987299ab81c8f3affd2ed8e1fc20f39a860b46e Mon Sep 17 00:00:00 2001 From: detachhead Date: Sat, 2 Nov 2024 16:01:36 +1000 Subject: [PATCH 3/3] =?UTF-8?q?fix=20import=20from=20statement=20=E2=80=BA?= =?UTF-8?q?=20rename=20module=20test=20(idk=20how=20it=20ever=20worked)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/pyright-internal/src/tests/languageServer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pyright-internal/src/tests/languageServer.test.ts b/packages/pyright-internal/src/tests/languageServer.test.ts index b65b577209..99f0117b57 100644 --- a/packages/pyright-internal/src/tests/languageServer.test.ts +++ b/packages/pyright-internal/src/tests/languageServer.test.ts @@ -777,7 +777,7 @@ describe(`Basic language server tests`, () => { const result = await serverInfo.connection.sendRequest( WillRenameFilesRequest.type, { - files: [{ oldUri: 'file:///src/foo/bar', newUri: 'file:///src/foo/bar2' }], + files: [{ oldUri: marker.fileUri.toString(), newUri: 'file:///src/foo/bar2.py' }], }, CancellationToken.None );