mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-06-13 07:10:26 +08:00
Remove old lsp example
This commit is contained in:
2
languageprovider-sample/.gitignore
vendored
2
languageprovider-sample/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
out
|
||||
node_modules
|
||||
55
languageprovider-sample/.vscode/launch.json
vendored
55
languageprovider-sample/.vscode/launch.json
vendored
@ -1,55 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceRoot}"
|
||||
],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/client/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "npm"
|
||||
},
|
||||
{
|
||||
"name": "Launch Extension Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceRoot}",
|
||||
"--extensionTestsPath=${workspaceRoot}/client/out/test"
|
||||
],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/client/out/test/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "npm"
|
||||
},
|
||||
{
|
||||
"name": "Attach Language Server",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"port": 6004,
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/server/out/**/*.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
"compounds": [
|
||||
{
|
||||
"name": "Launch Client & Server",
|
||||
"configurations": [
|
||||
"Launch Extension",
|
||||
"Attach Language Server"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
12
languageprovider-sample/.vscode/tasks.json
vendored
12
languageprovider-sample/.vscode/tasks.json
vendored
@ -1,12 +0,0 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "npm",
|
||||
"isShellCommand": true,
|
||||
"showOutput": "silent",
|
||||
"args": [
|
||||
"run",
|
||||
"watch"
|
||||
],
|
||||
"isBackground": true,
|
||||
"problemMatcher": "$tsc-watch"
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
# README
|
||||
## This is the README for the "languageprovider-sample"
|
||||
-------------------
|
||||
|
||||
This folder contains a sample VS code extension that demonstrates an extension that runs a language server
|
||||
|
||||
The extension observes all 'plaintext' documents (documents from all editors not associated with a language)
|
||||
and uses the server to provide validation and completion proposals.
|
||||
|
||||
The code for the extension is in the 'client' folder. It uses the 'vscode-languageclient' node module to launch the language server.
|
||||
|
||||
The language server is located in the 'server' folder.
|
||||
|
||||
|
||||
# How to run locally
|
||||
* `npm install` to initialize the extension and the server
|
||||
* `npm run compile` to compile the extension and the server
|
||||
* open this folder in VS Code. In the Debug viewlet, run 'Launch Client & Server' from drop-down to launch the extension and attach to both the extension and the server.
|
||||
* create a file `foo.bar`, and type `typescript`. You should see a validation error.
|
||||
* set breakpoints in the server or the client
|
||||
@ -1,44 +0,0 @@
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
'use strict';
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
import { workspace, Disposable, ExtensionContext } from 'vscode';
|
||||
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
|
||||
// The server is implemented in node
|
||||
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'serverMain.js'));
|
||||
// The debug options for the server
|
||||
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };
|
||||
|
||||
// If the extension is launched in debug mode then the debug server options are used
|
||||
// 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: ['plaintext'],
|
||||
synchronize: {
|
||||
// Synchronize the setting section 'languageServerExample' to the server
|
||||
configurationSection: 'languageServerExample',
|
||||
// Notify the server about file changes to '.clientrc files contain in the workspace
|
||||
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
|
||||
}
|
||||
}
|
||||
|
||||
// Create the language client and start the client.
|
||||
let disposable = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions).start();
|
||||
|
||||
// Push the disposable to the context's subscriptions so that the
|
||||
// client can be deactivated on extension deactivation
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"outDir": "./out",
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"lib": [
|
||||
"es5",
|
||||
"es2015.promise"
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
{
|
||||
"name": "languageprovider-sample",
|
||||
"description": "Language provider extension that launches a language server",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"version": "0.0.1",
|
||||
"publisher": "vscode",
|
||||
"engines": {
|
||||
"vscode": "^1.4.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onLanguage:plaintext"
|
||||
],
|
||||
"main": "./client/out/clientMain",
|
||||
"contributes": {
|
||||
"configuration": {
|
||||
"type": "object",
|
||||
"title": "Example configuration",
|
||||
"properties": {
|
||||
"languageServerExample.maxNumberOfProblems": {
|
||||
"type": "number",
|
||||
"default": 100,
|
||||
"description": "Controls the maximum number of problems produced by the server."
|
||||
},
|
||||
"languageServerExample.trace.server": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"off",
|
||||
"messages",
|
||||
"verbose"
|
||||
],
|
||||
"default": "off",
|
||||
"description": "Traces the communication between VSCode and the languageServerExample service."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "tsc -p ./",
|
||||
"compile": "tsc -p ./client && cd server && npm run compile && cd ..",
|
||||
"update-vscode": "node ./node_modules/vscode/bin/install",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install && cd server && npm install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^2.2.33",
|
||||
"@types/node": "^6.0.52",
|
||||
"typescript": "^2.1.4",
|
||||
"vscode": "^1.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-languageclient": "^2.6.3"
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
{
|
||||
"name": "language-server-example",
|
||||
"description": "Example implementation of a language server in node.",
|
||||
"version": "0.0.1",
|
||||
"author": "Microsoft Corporation",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-languageserver": "^2.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^6.0.52",
|
||||
"typescript": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "tsc -p .",
|
||||
"watch": "tsc --watch -p ."
|
||||
}
|
||||
}
|
||||
@ -1,153 +0,0 @@
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
'use strict';
|
||||
|
||||
import {
|
||||
IPCMessageReader, IPCMessageWriter,
|
||||
createConnection, IConnection, TextDocumentSyncKind,
|
||||
TextDocuments, TextDocument, Diagnostic, DiagnosticSeverity,
|
||||
InitializeParams, InitializeResult, TextDocumentPositionParams,
|
||||
CompletionItem, CompletionItemKind
|
||||
} from 'vscode-languageserver';
|
||||
|
||||
// Create a connection for the server. The connection uses Node's IPC as a transport
|
||||
let connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));
|
||||
|
||||
// Create a simple text document manager. The text document manager
|
||||
// supports full document sync only
|
||||
let documents: TextDocuments = new TextDocuments();
|
||||
// Make the text document manager listen on the connection
|
||||
// for open, change and close text document events
|
||||
documents.listen(connection);
|
||||
|
||||
// After the server has started the client sends an initilize request. The server receives
|
||||
// in the passed params the rootPath of the workspace plus the client capabilites.
|
||||
let workspaceRoot: string;
|
||||
connection.onInitialize((params): InitializeResult => {
|
||||
workspaceRoot = params.rootPath;
|
||||
return {
|
||||
capabilities: {
|
||||
// Tell the client that the server works in FULL text document sync mode
|
||||
textDocumentSync: documents.syncKind,
|
||||
// Tell the client that the server support code complete
|
||||
completionProvider: {
|
||||
resolveProvider: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// The content of a text document has changed. This event is emitted
|
||||
// when the text document first opened or when its content has changed.
|
||||
documents.onDidChangeContent((change) => {
|
||||
validateTextDocument(change.document);
|
||||
});
|
||||
|
||||
// The settings interface describe the server relevant settings part
|
||||
interface Settings {
|
||||
languageServerExample: ExampleSettings;
|
||||
}
|
||||
|
||||
// These are the example settings we defined in the client's package.json
|
||||
// file
|
||||
interface ExampleSettings {
|
||||
maxNumberOfProblems: number;
|
||||
}
|
||||
|
||||
// hold the maxNumberOfProblems setting
|
||||
let maxNumberOfProblems: number;
|
||||
// The settings have changed. Is send on server activation
|
||||
// as well.
|
||||
connection.onDidChangeConfiguration((change) => {
|
||||
let settings = <Settings>change.settings;
|
||||
maxNumberOfProblems = settings.languageServerExample.maxNumberOfProblems || 100;
|
||||
// Revalidate any open text documents
|
||||
documents.all().forEach(validateTextDocument);
|
||||
});
|
||||
|
||||
function validateTextDocument(textDocument: TextDocument): void {
|
||||
let diagnostics: Diagnostic[] = [];
|
||||
let lines = textDocument.getText().split(/\r?\n/g);
|
||||
let problems = 0;
|
||||
for (var i = 0; i < lines.length && problems < maxNumberOfProblems; i++) {
|
||||
let line = lines[i];
|
||||
let index = line.indexOf('typescript');
|
||||
if (index >= 0) {
|
||||
problems++;
|
||||
diagnostics.push({
|
||||
severity: DiagnosticSeverity.Warning,
|
||||
range: {
|
||||
start: { line: i, character: index },
|
||||
end: { line: i, character: index + 10 }
|
||||
},
|
||||
message: `${line.substr(index, 10)} should be spelled TypeScript`,
|
||||
source: 'ex'
|
||||
});
|
||||
}
|
||||
}
|
||||
// Send the computed diagnostics to VSCode.
|
||||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
||||
}
|
||||
|
||||
connection.onDidChangeWatchedFiles((change) => {
|
||||
// Monitored files have change in VSCode
|
||||
connection.console.log('We recevied an file change event');
|
||||
});
|
||||
|
||||
|
||||
// This handler provides the initial list of the completion items.
|
||||
connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
|
||||
// The pass parameter contains the position of the text document in
|
||||
// which code complete got requested. For the example we ignore this
|
||||
// info and always provide the same completion items.
|
||||
return [
|
||||
{
|
||||
label: 'TypeScript',
|
||||
kind: CompletionItemKind.Text,
|
||||
data: 1
|
||||
},
|
||||
{
|
||||
label: 'JavaScript',
|
||||
kind: CompletionItemKind.Text,
|
||||
data: 2
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
// This handler resolve additional information for the item selected in
|
||||
// the completion list.
|
||||
connection.onCompletionResolve((item: CompletionItem): CompletionItem => {
|
||||
if (item.data === 1) {
|
||||
item.detail = 'TypeScript details',
|
||||
item.documentation = 'TypeScript documentation'
|
||||
} else if (item.data === 2) {
|
||||
item.detail = 'JavaScript details',
|
||||
item.documentation = 'JavaScript documentation'
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
/*
|
||||
connection.onDidOpenTextDocument((params) => {
|
||||
// A text document got opened in VSCode.
|
||||
// params.uri uniquely identifies the document. For documents store on disk this is a file URI.
|
||||
// params.text the initial full content of the document.
|
||||
connection.console.log(`${params.textDocument.uri} opened.`);
|
||||
});
|
||||
connection.onDidChangeTextDocument((params) => {
|
||||
// The content of a text document did change in VSCode.
|
||||
// params.uri uniquely identifies the document.
|
||||
// params.contentChanges describe the content changes to the document.
|
||||
connection.console.log(`${params.textDocument.uri} changed: ${JSON.stringify(params.contentChanges)}`);
|
||||
});
|
||||
connection.onDidCloseTextDocument((params) => {
|
||||
// A text document got closed in VSCode.
|
||||
// params.uri uniquely identifies the document.
|
||||
connection.console.log(`${params.textDocument.uri} closed.`);
|
||||
});
|
||||
*/
|
||||
|
||||
// Listen on the connection
|
||||
connection.listen();
|
||||
@ -1,2 +0,0 @@
|
||||
// We need this until the LSP node libraries are on TS 2.x as well.
|
||||
interface Thenable<T> extends PromiseLike<T> {}
|
||||
@ -1,12 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"outDir": "./out",
|
||||
"sourceMap": true,
|
||||
"lib": [
|
||||
"es5",
|
||||
"es2015.promise"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user