Skip to content

Move rename functionality to the language server #2612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 79 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
997635a
LS symbol providers
Jun 8, 2018
f6c6276
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Jun 13, 2018
0a20fef
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Jun 19, 2018
660a627
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Jun 29, 2018
3813395
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Jul 3, 2018
d4fd3ab
Different ready wait
Jul 4, 2018
3a0bea4
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Jul 12, 2018
56bf688
Upgrade dependencies to latest LS
Jul 12, 2018
37f1154
Make open files only default
Jul 12, 2018
4092bcc
Turn off hash checks
Jul 12, 2018
49ec38a
Fix double progress display
Jul 12, 2018
f7e245b
Update packages
Jul 13, 2018
bdce0ff
Anchor dependencies
brettcannon Jul 13, 2018
969db02
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Aug 6, 2018
13828ca
Merge master
Aug 6, 2018
5d45558
Add setting for diag throttling
Aug 6, 2018
70b13f7
Add MacOS version check
Aug 7, 2018
462ff7c
News
Aug 7, 2018
4e12b3c
Correct MacOS check and lay infra for Linux checks
Aug 8, 2018
0d3c066
Linux version check
Aug 8, 2018
925f663
Linux check
Aug 8, 2018
fef0e92
Simplify
Aug 8, 2018
2c7243c
Test prep
Aug 8, 2018
07dc2fa
Platform tests
Aug 8, 2018
cd970be
Mac compat tests
Aug 8, 2018
c63c904
Ubuntu tests
Aug 9, 2018
42ebdd1
Revert "Ubuntu tests"
Aug 9, 2018
d3c7acb
Revert "Mac compat tests"
Aug 9, 2018
d86997b
Revert "Platform tests"
Aug 9, 2018
5caca65
Revert "Test prep"
Aug 9, 2018
983cbeb
Revert "Simplify"
Aug 9, 2018
0f116cc
Revert "Linux check"
Aug 9, 2018
cfc9b2d
Revert "Linux version check"
Aug 9, 2018
4fe1052
Revert "Correct MacOS check and lay infra for Linux checks"
Aug 9, 2018
c8dedc3
Revert "News"
Aug 9, 2018
5e40775
Revert "Add MacOS version check"
Aug 9, 2018
e63479b
News
Aug 9, 2018
e44afad
Format
Aug 9, 2018
d7cd632
Undo
Aug 9, 2018
d70322c
Pass async startup option to LS
Aug 10, 2018
ed8ac1b
News for LS fixes
Aug 10, 2018
c000856
News for LS fixes
Aug 10, 2018
0abe7b3
Merge master
Aug 10, 2018
3bd21b1
Remove issue that is not fixed
Aug 10, 2018
a399fc4
Add news
Aug 10, 2018
f0ab109
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Aug 10, 2018
6870109
News
Aug 10, 2018
adcd0ab
News
Aug 10, 2018
0756aef
News
Aug 13, 2018
9e40248
News
Aug 14, 2018
92df7f2
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Aug 15, 2018
40bac62
Drop typeshed submodule
Aug 16, 2018
b2546d1
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Aug 16, 2018
e0c4b87
Add settings to control LS output
Aug 16, 2018
1d1d7bf
News
Aug 16, 2018
8e11bea
Fix case
Aug 17, 2018
652ab22
Switch to 1.26 and LSP 4.4 for outline
Aug 20, 2018
2e92432
Merge branch 'master' of https://github.com/MikhailArkhipov/vscode-py…
Aug 20, 2018
83c356d
News
Aug 20, 2018
8c63050
News
Aug 20, 2018
797941b
Add package lock
Aug 20, 2018
e24c7e5
Update mock to 1.26
Aug 20, 2018
c3334c8
Tweak news entry wording
brettcannon Aug 21, 2018
a8b21ef
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Aug 21, 2018
e71199c
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Aug 24, 2018
613fd49
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Aug 27, 2018
f3a08aa
Move rope rename off common to Jedi
Aug 27, 2018
c51936c
Move Rename to LS
Aug 30, 2018
f67cbfa
Ref fix
Aug 30, 2018
d7f7ea6
Merge master
Sep 6, 2018
f4353dd
Update LS contrib
Sep 6, 2018
1b33dde
Merge issue
Sep 6, 2018
bfdc24a
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Sep 13, 2018
1187d7e
Make sure progress is cleared
Sep 13, 2018
1d19d2f
Revert "Make sure progress is cleared"
Sep 18, 2018
636b31b
Merge branch 'master' of https://github.com/Microsoft/vscode-python
Sep 18, 2018
0eb40d4
Merge branch 'rename'
Sep 18, 2018
1471e90
Line breaks and remove duplication
Sep 18, 2018
0b532c0
Add news
Sep 20, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/2650.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Language server now provides rename functionality.
5 changes: 2 additions & 3 deletions src/client/activation/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class LanguageServerDownloader {
deferred.reject(err);
})
.on('end', () => {
this.output.append('complete.');
this.output.appendLine('complete.');
deferred.resolve();
})
.pipe(fileStream);
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/client/activation/jedi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(IUnitTestManagementService);
testManagementService.activate()
.then(() => testManagementService.activateCodeLenses(symbolProvider))
Expand Down
6 changes: 2 additions & 4 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -87,9 +86,8 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
const configuration = serviceManager.get<IConfigurationService>(IConfigurationService);
const pythonSettings = configuration.getSettings();

const standardOutputChannel = serviceManager.get<OutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
context.subscriptions.push(languages.registerRenameProvider(PYTHON, new PythonRenameProvider(serviceManager)));
activateSimplePythonRefactorProvider(context, standardOutputChannel, serviceManager);
const standardOutputChannel = serviceContainer.get<OutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
activateSimplePythonRefactorProvider(context, standardOutputChannel, serviceContainer);

const activationService = serviceContainer.get<IExtensionActivationService>(IExtensionActivationService);
await activationService.activate();
Expand Down
23 changes: 13 additions & 10 deletions src/client/providers/renameProvider.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<OutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
}
@captureTelemetry(REFACTOR_RENAME)
public provideRenameEdits(document: vscode.TextDocument, position: vscode.Position, newName: string, token: vscode.CancellationToken): ProviderResult<vscode.WorkspaceEdit> {
return vscode.workspace.saveAll(false).then(() => {
public provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit> {
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<vscode.WorkspaceEdit> {
private doRename(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit> {
if (document.lineAt(position.line).text.match(/^\s*\/\//)) {
return;
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down