本文整理汇总了TypeScript中vscode-languageclient.LanguageClient.onRequest方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LanguageClient.onRequest方法的具体用法?TypeScript LanguageClient.onRequest怎么用?TypeScript LanguageClient.onRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode-languageclient.LanguageClient
的用法示例。
在下文中一共展示了LanguageClient.onRequest方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setLanguageClient
public setLanguageClient(languageClient: LanguageClient) {
this.languageClient = languageClient;
this.languageClient.onRequest(
ShowChoicePromptRequestType,
(promptDetails) => showChoicePrompt(promptDetails, this.languageClient));
this.languageClient.onRequest(
ShowInputPromptRequestType,
(promptDetails) => showInputPrompt(promptDetails, this.languageClient));
// Set up status bar alerts for when PowerShell is executing a script
this.languageClient.onNotification(
ExecutionStatusChangedNotificationType,
(executionStatusDetails) => {
switch (executionStatusDetails.executionStatus) {
// If execution has changed to running, make a notification
case ExecutionStatus.Running:
this.showExecutionStatus("PowerShell");
break;
// If the execution has stopped, destroy the previous notification
case ExecutionStatus.Completed:
case ExecutionStatus.Aborted:
case ExecutionStatus.Failed:
this.clearStatusBar();
break;
}
});
}
示例2: registerExtensionCommands
export function registerExtensionCommands(client: LanguageClient): void {
vscode.commands.registerCommand('PowerShell.ShowAdditionalCommands', () => {
var editor = vscode.window.activeTextEditor;
var start = editor.selection.start;
var end = editor.selection.end;
if (editor.selection.isEmpty) {
start = new vscode.Position(start.line, 0)
}
showExtensionCommands(client);
});
client.onNotification(
ExtensionCommandAddedNotification.type,
command => addExtensionCommand(command));
client.onRequest(
GetEditorContextRequest.type,
details => getEditorContext());
client.onRequest(
InsertTextRequest.type,
details => insertText(details));
client.onRequest(
SetSelectionRequest.type,
details => setSelection(details));
client.onRequest(
OpenFileRequest.type,
filePath => openFile(filePath));
}
示例3:
client.onDidChangeState(e => {
if (e.newState === State.Running) {
client.onRequest(Methods.readConfiguration, configFromUrl)
client.onRequest(Methods.objectDetails, objectDetailFromUrl)
client.onRequest(Methods.readEditorObjectSource, readEditorObjectSource)
client.onRequest(Methods.readObjectSourceOrMain, readObjectSource)
client.onRequest(Methods.vsUri, getVSCodeUri)
}
})
示例4: activate
export function activate(context: ExtensionContext)
{
let qol: QualityOfLife = new QualityOfLife();
let serverModule = context.asAbsolutePath(path.join("server", "server.js"));
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };
let serverOptions: ServerOptions = {
run : { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
}
let clientOptions: LanguageClientOptions = {
documentSelector: ["php"],
synchronize: {
configurationSection: "languageServerExample",
fileEvents: workspace.createFileSystemWatcher("**/.clientrc")
}
}
// Create the language client and start the client.
var langClient: LanguageClient = new LanguageClient("Crane Language Server", serverOptions, clientOptions);
// Use this to handle a request sent from the server
// https://github.com/Microsoft/vscode/blob/80bd73b5132268f68f624a86a7c3e56d2bbac662/extensions/json/client/src/jsonMain.ts
// https://github.com/Microsoft/vscode/blob/580d19ab2e1fd6488c3e515e27fe03dceaefb819/extensions/json/server/src/server.ts
//langClient.onRequest()
let disposable = langClient.start();
let crane: Crane = new Crane(langClient);
var requestType: RequestType<any, any, any> = { method: "workDone" };
langClient.onRequest(requestType, () => {
// Load settings
let craneSettings = workspace.getConfiguration("crane");
if (craneSettings) {
var showStatusBarItem = craneSettings.get<boolean>("showStatusBarBugReportLink", true);
if (showStatusBarItem) {
setTimeout(() => {
crane.statusBarItem.text = "$(bug) Report PHP Intellisense Bug";
crane.statusBarItem.tooltip = "Found a problem with the PHP Intellisense provided by Crane? Click here to file a bug report on Github";
crane.statusBarItem.command = "crane.reportBug";
crane.statusBarItem.show();
}, 5000);
} else {
crane.statusBarItem.hide();
}
} else {
crane.statusBarItem.hide();
}
});
// Register commands for QoL improvements
let duplicateLineCommand = commands.registerCommand("crane.duplicateLine", qol.duplicateLineOrSelection);
let reportBugCommand = commands.registerCommand("crane.reportBug", crane.reportBug);
context.subscriptions.push(disposable);
context.subscriptions.push(duplicateLineCommand);
}
示例5: LanguageClient
languages.getLanguages().then(languageIds => {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'jsonServerMain.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for json documents
documentSelector: ['json'],
synchronize: {
// Synchronize the setting section 'json' to the server
configurationSection: ['json.schemas', 'http.proxy', 'http.proxyStrictSSL'],
fileEvents: workspace.createFileSystemWatcher('**/*.json')
},
initializationOptions: {
languageIds,
['format.enable']: workspace.getConfiguration('json').get('format.enable')
}
};
// Create the language client and start the client.
let client = new LanguageClient('json', localize('jsonserver.name', 'JSON Language Server'), serverOptions, clientOptions);
client.onTelemetry(e => {
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data);
}
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
let disposable = client.start();
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
languages.setLanguageConfiguration('json', {
wordPattern: /("(?:[^\\\"]*(?:\\.)?)*"?)|[^\s{}\[\],:]+/
});
});
示例6: activate
export function activate(context: ExtensionContext) {
workspace.getConfiguration()
let serverModule = context.asAbsolutePath(path.join('server', 'server.js'));
let debugOptions = {execArgv: ["--nolazy", "--debug=6004"]};
let serverOptions:ServerOptions = {
run: {module: serverModule, transport: TransportKind.ipc},
debug: {module: serverModule, transport: TransportKind.ipc, options: debugOptions}
}
// Options to control the language client
let clientOptions:LanguageClientOptions = {
//documentSelector: ['raml'],
documentSelector: ['raml'],
synchronize: {
configurationSection: 'languageServerExample'
//fileEvents: workspace.createFileSystemWatcher('**/*.*')
}
}
let client = new LanguageClient('Language Server Example', serverOptions, clientOptions);
client.onRequest({method: "content"}, (request:any) => {
var content = fs.existsSync(request.uri) ? fs.readFileSync(request.uri).toString() : null;
return {content: content};
})
client.onRequest({method: "list"}, (request:any) => {
var content = fs.existsSync(request.uri) ? fs.readdirSync(request.uri).toString() : [];
return {list: content};
})
client.onRequest({method: "savecontent"}, (request:any) => {
fs.writeFileSync(request.uri, request.content);
return {};
})
let disposable = client.start();
context.subscriptions.push(disposable);
}
示例7: registerConsoleCommands
export function registerConsoleCommands(client: LanguageClient): void {
vscode.commands.registerCommand('PowerShell.RunSelection', () => {
var editor = vscode.window.activeTextEditor;
var selectionRange: vscode.Range = undefined;
if (!editor.selection.isEmpty) {
selectionRange =
new vscode.Range(
editor.selection.start,
editor.selection.end);
}
else {
selectionRange = editor.document.lineAt(editor.selection.start.line).range;
}
client.sendRequest(EvaluateRequest.type, {
expression: editor.document.getText(selectionRange)
});
});
var consoleChannel = vscode.window.createOutputChannel("PowerShell Output");
client.onNotification(OutputNotification.type, (output) => {
var outputEditorExist = vscode.window.visibleTextEditors.some((editor) => {
return editor.document.languageId == 'Log'
});
if (!outputEditorExist)
consoleChannel.show(vscode.ViewColumn.Three);
consoleChannel.append(output.output);
});
var t: Thenable<ShowChoicePromptResponseBody>;
client.onRequest(
ShowChoicePromptRequest.type,
promptDetails => showChoicePrompt(promptDetails, client));
client.onRequest(
ShowInputPromptRequest.type,
promptDetails => showInputPrompt(promptDetails, client));
}
示例8: activate
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for json documents
documentSelector: ['json'],
synchronize: {
// Synchronize the setting section 'json' to the server
configurationSection: ['json.schemas', 'http.proxy', 'http.proxyStrictSSL'],
fileEvents: workspace.createFileSystemWatcher('**/.json')
}
};
// Create the language client and start the client.
let client = new LanguageClient('JSON Server', serverOptions, clientOptions);
client.onNotification(TelemetryNotification.type, (e) => {
// to be done
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
let disposable = client.start();
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
languages.setLanguageConfiguration('json', {
wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g
});
}
示例9: activate
export function activate(context: ExtensionContext): void {
setLogLevel();
workspace.onDidChangeConfiguration(setLogLevel);
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'src', 'server.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run : { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: ['haskell'],
synchronize: {
// Synchronize the setting section 'ghcMod' to the server
configurationSection: 'haskell'
}
};
// Create the language client and start the client.
let languageClient = new LanguageClient('ghc-mod server', serverOptions, clientOptions);
let disposable = languageClient.start();
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
Commands.register(context, languageClient);
languageClient.onRequest<string, string, void>(OpenSettingsRequest.type, (action): Promise<string> => {
switch (action) {
case 'Workspace':
commands.executeCommand('workbench.action.openWorkspaceSettings');
break;
case 'User':
commands.executeCommand('workbench.action.openGlobalSettings');
break;
default:
break;
}
return null;
});
}
示例10: initialize
public initialize(): void {
this.client.onRequest(
WorkspaceRubyEnvironmentRequest.type,
async (params: WorkspaceRubyEnvironmentParams): Promise<WorkspaceRubyEnvironmentResult> => {
const environments: WorkspaceRubyEnvironmentResult = {};
for (const uri of params.folders) {
const workspaceFolder: WorkspaceFolder = workspace.getWorkspaceFolder(Uri.parse(uri));
if (workspaceFolder && workspaceFolder.uri.fsPath) {
environments[uri] = await loadEnv(workspaceFolder.uri.fsPath);
}
}
return environments;
}
);
}
示例11: getSchemaAssociation
client.onReady().then(() => {
client.onTelemetry(e => {
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data);
}
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
});
示例12: LanguageClient
languages.getLanguages().then(languageIds => {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'jsonServerMain.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for json documents
documentSelector: ['json'],
synchronize: {
// Synchronize the setting section 'json' to the server
configurationSection: ['json.schemas', 'http.proxy', 'http.proxyStrictSSL'],
fileEvents: workspace.createFileSystemWatcher('**/*.json')
},
initializationOptions: {
languageIds
}
};
// Create the language client and start the client.
let client = new LanguageClient('JSON Server', serverOptions, clientOptions);
client.onTelemetry(e => {
if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data);
}
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
let disposable = client.start();
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
languages.setLanguageConfiguration('json', {
wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] },
{ open: '`', close: '`', notIn: ['string', 'comment'] }
]
}
});
});
示例13: LanguageClient
languages.getLanguages().then(languageIds => {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'server.js'));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--debug=6004'] };
// If the extension is launch in debug mode the debug server options are use
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for yaml documents
documentSelector: ['yaml'],
synchronize: {
configurationSection: ['json.schemas', 'http.proxy', 'http.proxyStrictSSL', 'languageServerYamlSchema'],
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
// fileEvents: workspace.createFileSystemWatcher('**/.yaml')
},
initializationOptions: {
languageIds
}
};
// Create the language client and start the client.
let client = new LanguageClient('Language Server YAML Schema', serverOptions, clientOptions);
client.onNotification(TelemetryNotification.type, e => {
// if (telemetryReporter) {
// telemetryReporter.sendTelemetryEvent(e.key, e.data);
// }
});
// handle content request
client.onRequest(VSCodeContentRequest.type, (uriPath: string) => {
let uri = Uri.parse(uriPath);
return workspace.openTextDocument(uri).then(doc => {
return doc.getText();
}, error => {
return Promise.reject(error);
});
});
let disposable = client.start();
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable);
languages.setLanguageConfiguration('yaml', {
comments: {
"lineComment": "#"
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
]
});
});