diff --git a/package.json b/package.json index c4c70bb6..6b67f46d 100644 --- a/package.json +++ b/package.json @@ -31,13 +31,22 @@ "command": "sourcery.refactor.workspace", "title": "Scan with Sourcery", "category": "Sourcery" + }, + { + "command": "sourcery.clones.workspace", + "title": "Detect clones", + "category": "Sourcery" } ], "menus": { "explorer/context": [ { "command": "sourcery.refactor.workspace", - "group": "1_modification" + "group": "1_modification@1" + }, + { + "command": "sourcery.clones.workspace", + "group": "1_modification@2" } ] }, diff --git a/src/extension.ts b/src/extension.ts index 5340cfa9..dd576cba 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -16,19 +16,19 @@ const REFACTOR_WORKSPACE_REQUEST = new RequestType('refactor_workspace'); function createLangServer(context: ExtensionContext): LanguageClient { - const token = workspace.getConfiguration("sourcery").get("token"); + const token = workspace.getConfiguration('sourcery').get('token'); const packageJson = extensions.getExtension('sourcery.sourcery').packageJSON; const extensionVersion = packageJson.version; const sourceryVersion = packageJson.sourceryVersion; const command = path.join(__dirname, "..", "binaries/sourcery-" + sourceryVersion + "-" + getOperatingSystem()); - + const serverOptions: ServerOptions = { command, args: ['lsp'], options: { env: { - PYTHONHASHSEED: "0", + PYTHONHASHSEED: '0', ...process.env } } @@ -37,7 +37,7 @@ function createLangServer(context: ExtensionContext): LanguageClient { const clientOptions: LanguageClientOptions = { documentSelector: ['python'], synchronize: { - configurationSection: "sourcery" + configurationSection: 'sourcery' }, initializationOptions: { 'token': token, @@ -48,7 +48,7 @@ function createLangServer(context: ExtensionContext): LanguageClient { if (!token) { const readmePath = Uri.file( - path.join(context.extensionPath, "INSTALL.py") + path.join(context.extensionPath, 'INSTALL.py') ); window.showTextDocument(readmePath); const result = window.showInputBox({ @@ -57,14 +57,14 @@ function createLangServer(context: ExtensionContext): LanguageClient { ignoreFocusOut: true }); result.then(function (value) { - workspace.getConfiguration("sourcery").update('token', value, true) + workspace.getConfiguration('sourcery').update('token', value, true) }); } - return new LanguageClient(command, serverOptions, clientOptions); } + function getOperatingSystem(): string { if (process.platform == 'win32') { return 'win/sourcery.exe' @@ -76,25 +76,32 @@ function getOperatingSystem(): string { } } -let languageClient: LanguageClient; export function activate(context: ExtensionContext) { + const languageClient = createLangServer(context) - const command = 'sourcery.refactor.workspace'; - - languageClient = createLangServer(context) + context.subscriptions.push(commands.registerCommand('sourcery.refactor.workspace', (resource: Uri, selected?: Uri[]) => { + let request: ExecuteCommandParams = { + command: 'refactor_workspace', + arguments: [{ + 'uri': resource, + 'all_uris': selected + }] + }; + languageClient.sendRequest(ExecuteCommandRequest.type, request); + })); - const commandHandler = (resource: Uri) => { + context.subscriptions.push(commands.registerCommand('sourcery.clones.workspace', (resource: Uri, selected?: Uri[]) => { let request: ExecuteCommandParams = { - command: "refactor_workspace", + command: 'detect_clones', arguments: [{ - 'uri': resource + 'uri': resource, + 'all_uris': selected }] }; languageClient.sendRequest(ExecuteCommandRequest.type, request); - }; + })); - context.subscriptions.push(commands.registerCommand(command, commandHandler)); context.subscriptions.push(languageClient.start()); }