本文整理汇总了TypeScript中vscode-languageclient.LanguageClient.onNotification方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LanguageClient.onNotification方法的具体用法?TypeScript LanguageClient.onNotification怎么用?TypeScript LanguageClient.onNotification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode-languageclient.LanguageClient
的用法示例。
在下文中一共展示了LanguageClient.onNotification方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: activate
export function activate(context: ExtensionContext) {
// 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 },
debug: { module: serverModule, options: debugOptions }
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for php documents
documentSelector: ['php'],
synchronize: {
// Synchronize the setting section 'phpcs' to the server
configurationSection: 'phpcs',
// Notify the server about file changes to 'phpcs.xml' files contain in the workspace
fileEvents: workspace.createFileSystemWatcher('**/phpcs.xml')
}
};
// Create the language client the client.
let client = new LanguageClient('PHP CodeSniffer Linter', serverOptions, clientOptions);
// Create the save handler.
let saveHandler = workspace.onDidSaveTextDocument(document => {
if (document.languageId != `php`) {
return;
}
let params: proto.TextDocumentIdentifier = { uri: document.uri.toString() };
client.sendNotification<proto.TextDocumentIdentifier>(proto.DidSaveTextDocumentNotification.type, params);
});
let status = new PhpcsStatus();
client.onNotification( proto.DidStartValidateTextDocumentNotification.type, (document) => {
status.startProcessing(document.uri);
});
client.onNotification( proto.DidEndValidateTextDocumentNotification.type, (document) => {
status.endProcessing(document.uri);
});
context.subscriptions.push(saveHandler);
// Create the settings monitor and start the monitor for the client.
let monitor = new SettingMonitor(client, 'phpcs.enable').start();
// Push the monitor to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(monitor);
context.subscriptions.push(status);
}
示例2:
this.languageClient.onDidChangeState(event => {
if (event.newState === State.Running) {
this.languageClient.onNotification('rustDocument/diagnosticsBegin', () => {
this.statusBarItem.setText('Analysis started');
});
this.languageClient.onNotification('rustDocument/diagnosticsEnd', () => {
this.statusBarItem.setText('Analysis finished');
});
}
});
示例3: processAllFilesInWorkspace
private processAllFilesInWorkspace()
{
if (workspace.rootPath == undefined) return;
var fileProcessCount = 0;
// Find all the php files to process
workspace.findFiles('**/*.php', '').then(files => {
console.log(`Files to parse: ${files.length}`);
fileProcessCount = files.length;
var filePaths: string[] = [];
// Get the objects path value for the current file system
files.forEach(file => { filePaths.push(file.fsPath); });
// Send the array of paths to the language server
this.langClient.sendRequest({ method: "buildFromFiles" }, { files: filePaths });
});
// Update the UI so the user knows the processing status
var fileProcessed: NotificationType<any> = { method: "fileProcessed" };
this.langClient.onNotification(fileProcessed, data => {
// Get the percent complete
var percent:string = ((data.total / fileProcessCount) * 100).toFixed(2);
this.statusBarItem.text = `$(zap) Processing source files (${data.total} of ${fileProcessCount} / ${percent}%)`;
// Once all files have been processed, update the statusBarItem
if(data.total == fileProcessCount){
this.statusBarItem.text = 'File Processing Complete';
}
});
}
示例4: 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;
}
});
}
示例5: 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));
}
示例6: createProgressListeners
function createProgressListeners(client: LanguageClient) {
// Create a "checking files" progress indicator
let progressListener = new class {
progress: Progress<{message: string, increment?: number}>
resolve: (nothing: {}) => void
startProgress(message: string) {
if (this.progress != null)
this.endProgress();
window.withProgress({title: message, location: ProgressLocation.Notification}, progress => new Promise((resolve, _reject) => {
this.progress = progress;
this.resolve = resolve;
}));
}
reportProgress(message: string, increment: number) {
if (increment == -1)
this.progress.report({message});
else
this.progress.report({message, increment})
}
endProgress() {
if (this.progress != null) {
this.resolve({});
this.progress = null;
this.resolve = null;
}
}
}
// Use custom notifications to drive progressListener
client.onNotification(new NotificationType('java/startProgress'), (event: ProgressMessage) => {
progressListener.startProgress(event.message);
});
client.onNotification(new NotificationType('java/reportProgress'), (event: ProgressMessage) => {
progressListener.reportProgress(event.message, event.increment);
});
client.onNotification(new NotificationType('java/endProgress'), () => {
progressListener.endProgress();
});
}
示例7: 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
});
}
示例8: processAllFilesInWorkspace
private processAllFilesInWorkspace()
{
if (workspace.rootPath == undefined) return;
var fileProcessCount = 0;
let craneSettings = workspace.getConfiguration("crane");
let debugMode = false;
if (craneSettings) {
debugMode = craneSettings.get<boolean>("debugMode", false);
}
// Find all the php files to process
workspace.findFiles('**/*.php', '').then(files => {
console.log(`Files to parse: ${files.length}`);
Debug.info(`Preparing to parse ${files.length} PHP source files...`);
fileProcessCount = files.length;
var filePaths: string[] = [];
// Get the objects path value for the current file system
files.forEach(file => {
filePaths.push(file.fsPath);
});
// Send the array of paths to the language server
this.langClient.sendRequest({ method: "buildFromFiles" }, { files: filePaths });
});
// Update the UI so the user knows the processing status
var fileProcessed: NotificationType<any> = { method: "fileProcessed" };
this.langClient.onNotification(fileProcessed, data => {
// Get the percent complete
var percent: string = ((data.total / fileProcessCount) * 100).toFixed(2);
this.statusBarItem.text = `$(zap) Processing source files (${data.total} of ${fileProcessCount} / ${percent}%)`;
if (data.error) {
Debug.error("There was a problem parsing PHP file: " + data.filename);
Debug.error(data.error);
} else {
Debug.info(`Parsed file ${data.total} of ${fileProcessCount} : ${data.filename}`);
}
// Once all files have been processed, update the statusBarItem
if (data.total == fileProcessCount){
Debug.info("Processing complete!");
this.statusBarItem.text = '$(check) Processing of PHP source files complete';
}
});
}
示例9: 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));
}
示例10: setup
export function setup(context: ExtensionContext, client: LanguageClient)
{
context.subscriptions.push(content_provider.register())
language_client = client
language_client.onNotification(protocol.preview_response_type, params =>
{
const preview_uri = encode_preview(Uri.parse(params.uri))
if (preview_uri) {
content_provider.set_content(preview_uri, params.content)
content_provider.update(preview_uri)
const existing_document =
workspace.textDocuments.find(document =>
document.uri.scheme === preview_uri.scheme &&
document.uri.query === preview_uri.query)
if (!existing_document && params.column != 0) {
commands.executeCommand("vscode.previewHtml", preview_uri, params.column, params.label)
}
}
})
}