diff --git a/news/1 Enhancements/2650.md b/news/1 Enhancements/2650.md new file mode 100644 index 000000000000..e4df2bd4ea44 --- /dev/null +++ b/news/1 Enhancements/2650.md @@ -0,0 +1 @@ +Language server now provides rename functionality. \ No newline at end of file diff --git a/src/client/activation/downloader.ts b/src/client/activation/downloader.ts index 4443814175ee..a82bc42d1460 100644 --- a/src/client/activation/downloader.ts +++ b/src/client/activation/downloader.ts @@ -119,7 +119,7 @@ export class LanguageServerDownloader { deferred.reject(err); }) .on('end', () => { - this.output.append('complete.'); + this.output.appendLine('complete.'); deferred.resolve(); }) .pipe(fileStream); @@ -137,8 +137,7 @@ export class LanguageServerDownloader { const title = 'Extracting files... '; await window.withProgress({ - location: ProgressLocation.Window, - title + location: ProgressLocation.Window }, (progress) => { const zip = new StreamZip({ file: tempFilePath, diff --git a/src/client/activation/jedi.ts b/src/client/activation/jedi.ts index d839f3e4c48a..8eb5608cd30c 100644 --- a/src/client/activation/jedi.ts +++ b/src/client/activation/jedi.ts @@ -58,6 +58,8 @@ export class JediExtensionActivator implements IExtensionActivator { context.subscriptions.push(languages.registerSignatureHelpProvider(this.documentSelector, new PythonSignatureProvider(jediFactory), '(', ',')); } + context.subscriptions.push(languages.registerRenameProvider(PYTHON, new PythonRenameProvider(serviceContainer))); + const testManagementService = this.serviceManager.get(IUnitTestManagementService); testManagementService.activate() .then(() => testManagementService.activateCodeLenses(symbolProvider)) diff --git a/src/client/extension.ts b/src/client/extension.ts index e90aff0db75f..66986f0996c1 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -48,7 +48,6 @@ import { ILintingEngine } from './linters/types'; import { PythonCodeActionProvider } from './providers/codeActionsProvider'; import { PythonFormattingEditProvider } from './providers/formatProvider'; import { LinterProvider } from './providers/linterProvider'; -import { PythonRenameProvider } from './providers/renameProvider'; import { ReplProvider } from './providers/replProvider'; import { registerTypes as providersRegisterTypes } from './providers/serviceRegistry'; import { activateSimplePythonRefactorProvider } from './providers/simpleRefactorProvider'; @@ -87,9 +86,8 @@ export async function activate(context: ExtensionContext): Promise(IConfigurationService); const pythonSettings = configuration.getSettings(); - const standardOutputChannel = serviceManager.get(IOutputChannel, STANDARD_OUTPUT_CHANNEL); - context.subscriptions.push(languages.registerRenameProvider(PYTHON, new PythonRenameProvider(serviceManager))); - activateSimplePythonRefactorProvider(context, standardOutputChannel, serviceManager); + const standardOutputChannel = serviceContainer.get(IOutputChannel, STANDARD_OUTPUT_CHANNEL); + activateSimplePythonRefactorProvider(context, standardOutputChannel, serviceContainer); const activationService = serviceContainer.get(IExtensionActivationService); await activationService.activate(); diff --git a/src/client/providers/renameProvider.ts b/src/client/providers/renameProvider.ts index 827a4b213a3e..c440b2e8b777 100644 --- a/src/client/providers/renameProvider.ts +++ b/src/client/providers/renameProvider.ts @@ -1,6 +1,9 @@ import * as path from 'path'; -import * as vscode from 'vscode'; -import { OutputChannel, ProviderResult } from 'vscode'; +import { + CancellationToken, OutputChannel, + Position, ProviderResult, RenameProvider, + TextDocument, window, workspace, WorkspaceEdit +} from 'vscode'; import { PythonSettings } from '../common/configSettings'; import { STANDARD_OUTPUT_CHANNEL } from '../common/constants'; import { getWorkspaceEditsFromPatch } from '../common/editor'; @@ -15,19 +18,19 @@ type RenameResponse = { results: [{ diff: string }]; }; -export class PythonRenameProvider implements vscode.RenameProvider { +export class PythonRenameProvider implements RenameProvider { private readonly outputChannel: OutputChannel; constructor(private serviceContainer: IServiceContainer) { this.outputChannel = serviceContainer.get(IOutputChannel, STANDARD_OUTPUT_CHANNEL); } @captureTelemetry(REFACTOR_RENAME) - public provideRenameEdits(document: vscode.TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): ProviderResult { - return vscode.workspace.saveAll(false).then(() => { + public provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult { + return workspace.saveAll(false).then(() => { return this.doRename(document, position, newName, token); }); } - private doRename(document: vscode.TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): ProviderResult { + private doRename(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult { if (document.lineAt(position.line).text.match(/^\s*\/\//)) { return; } @@ -44,9 +47,9 @@ export class PythonRenameProvider implements vscode.RenameProvider { return; } - let workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri); - if (!workspaceFolder && Array.isArray(vscode.workspace.workspaceFolders) && vscode.workspace.workspaceFolders.length > 0) { - workspaceFolder = vscode.workspace.workspaceFolders[0]; + let workspaceFolder = workspace.getWorkspaceFolder(document.uri); + if (!workspaceFolder && Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0) { + workspaceFolder = workspace.workspaceFolders[0]; } const workspaceRoot = workspaceFolder ? workspaceFolder.uri.fsPath : __dirname; const pythonSettings = PythonSettings.getInstance(workspaceFolder ? workspaceFolder.uri : undefined); @@ -62,7 +65,7 @@ export class PythonRenameProvider implements vscode.RenameProvider { .catch(ex => console.error('Python Extension: promptToInstall', ex)); return Promise.reject(''); } else { - vscode.window.showErrorMessage(reason); + window.showErrorMessage(reason); this.outputChannel.appendLine(reason); } return Promise.reject(reason);