PT-160007578: Check if commands exist before registering in vscode
This commit is contained in:
@@ -208,7 +208,7 @@ public class LiveHoverUtils {
|
||||
codeLens.setData(sb.toString());
|
||||
Command cmd = new Command();
|
||||
cmd.setTitle(sb.toString());
|
||||
cmd.setCommand("org.springframework.showHoverAtPosition");
|
||||
cmd.setCommand("sts.showHoverAtPosition");
|
||||
cmd.setArguments(ImmutableList.of(range.getStart()));
|
||||
codeLens.setCommand(cmd);
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ public class RequestMappingHoverProvider implements HoverProvider {
|
||||
codeLens.setData(content);
|
||||
cmd.setTitle(content);
|
||||
|
||||
cmd.setCommand("springboot.open.url");
|
||||
cmd.setCommand("sts.open.url");
|
||||
cmd.setArguments(ImmutableList.of(content));
|
||||
}
|
||||
|
||||
|
||||
38
vscode-extensions/commons-vscode/src/commands.ts
Normal file
38
vscode-extensions/commons-vscode/src/commands.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
import * as VSCode from 'vscode';
|
||||
import { Position } from 'vscode-languageclient';
|
||||
|
||||
|
||||
|
||||
export function registerCommands(context: VSCode.ExtensionContext) {
|
||||
VSCode.commands.getCommands(true).then(commands => {
|
||||
if (!commandExists(commands, "sts.open.url")) {
|
||||
registerOpenUrl(context, "sts.open.url");
|
||||
}
|
||||
|
||||
if (!commandExists(commands, "sts.showHoverAtPosition")) {
|
||||
registerShowHoverAtPosition(context, "sts.showHoverAtPosition");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function registerOpenUrl(context: VSCode.ExtensionContext, commandId: string) {
|
||||
context.subscriptions.push(VSCode.commands.registerCommand(commandId, (url) => {
|
||||
VSCode.commands.executeCommand('vscode.open', VSCode.Uri.parse(url))
|
||||
}));
|
||||
}
|
||||
|
||||
function registerShowHoverAtPosition(context: VSCode.ExtensionContext, commandId: string) {
|
||||
VSCode.commands.registerCommand(commandId, (position: Position) => {
|
||||
const editor = VSCode.window.activeTextEditor;
|
||||
const vsPosition = new VSCode.Position(position.line, position.character);
|
||||
editor.selection = new VSCode.Selection(vsPosition, vsPosition);
|
||||
VSCode.commands.executeCommand('editor.action.showHover');
|
||||
});
|
||||
}
|
||||
|
||||
function commandExists(commands: string[], commandId: string) {
|
||||
return commands.indexOf(commandId) >= 0;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import * as FS from 'fs';
|
||||
import PortFinder = require('portfinder');
|
||||
import * as Net from 'net';
|
||||
import * as ChildProcess from 'child_process';
|
||||
import * as CommonsCommands from './commands';
|
||||
import { TextDocumentIdentifier, RequestType, LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, StreamInfo, Position } from 'vscode-languageclient';
|
||||
import {TextDocument, OutputChannel, Disposable, window, Event, EventEmitter} from 'vscode';
|
||||
import { Trace, NotificationType } from 'vscode-jsonrpc';
|
||||
@@ -211,12 +212,7 @@ function setupLanguageClient(context: VSCode.ExtensionContext, createServer: Ser
|
||||
const codelensService = new HighlightCodeLensProvider();
|
||||
let codeLensProviderSubscription: Disposable;
|
||||
|
||||
VSCode.commands.registerCommand('org.springframework.showHoverAtPosition', (position: Position) => {
|
||||
const editor = VSCode.window.activeTextEditor;
|
||||
const vsPosition = new VSCode.Position(position.line, position.character);
|
||||
editor.selection = new VSCode.Selection(vsPosition, vsPosition);
|
||||
VSCode.commands.executeCommand('editor.action.showHover');
|
||||
});
|
||||
CommonsCommands.registerCommands(context);
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
context.subscriptions.push(progressService);
|
||||
|
||||
@@ -16,7 +16,6 @@ const JAVA_LANGUAGE_ID = "java";
|
||||
export function activate(context: VSCode.ExtensionContext): Thenable<LanguageClient> {
|
||||
|
||||
// registerPipelineGenerator(context);
|
||||
registerOpenUrl(context);
|
||||
let options : commons.ActivatorOptions = {
|
||||
DEBUG: false,
|
||||
CONNECT_TO_LS: false,
|
||||
@@ -84,10 +83,3 @@ function registerPipelineGenerator(context: VSCode.ExtensionContext) {
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
function registerOpenUrl(context: VSCode.ExtensionContext) {
|
||||
context.subscriptions.push(VSCode.commands.registerCommand('springboot.open.url', (url) => {
|
||||
VSCode.commands.executeCommand('vscode.open', VSCode.Uri.parse(url))
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user