Skip to content

Commit 170f24a

Browse files
committed
add language-provider sample
1 parent b41b561 commit 170f24a

16 files changed

+453
-5
lines changed

.vscode/launch.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,30 @@
3434
"sourceMaps": true,
3535
"outFiles": ["${workspaceRoot}/contentprovider-sample/out/**/*.js"],
3636
"preLaunchTask": "compile-contentprovider"
37+
},
38+
{
39+
"name": "Launch Language Provider Sample",
40+
"type": "extensionHost",
41+
"request": "launch",
42+
"runtimeExecutable": "${execPath}",
43+
"args": ["--extensionDevelopmentPath=${workspaceRoot}/languageprovider-sample" ],
44+
"stopOnEntry": false,
45+
"sourceMaps": true,
46+
"outFiles": ["${workspaceRoot}/languageprovider-sample/client/out/**/*.js"]
47+
},
48+
{
49+
"name": "Attach Language Provider Sample Server",
50+
"type": "node",
51+
"request": "attach",
52+
"port": 6004,
53+
"sourceMaps": true,
54+
"outFiles": ["${workspaceRoot}/languageprovider-sample/server/out/**/*.js"]
3755
}
38-
]
56+
],
57+
"compounds": [
58+
{
59+
"name": "Launch Language Provider Sample & Attach to Server",
60+
"configurations": ["Launch Language Provider Sample", "Attach Language Provider Sample Server"]
61+
}
62+
]
3963
}

.vscode/tasks.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@
5656
// The tsc compiler is started in watching mode
5757
"isWatching": true,
5858

59+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
60+
"problemMatcher": "$tsc-watch"
61+
},
62+
{
63+
// in package.json we have a compile task for each example
64+
"taskName": "compile-languageprovider",
65+
66+
// show the output window only if unrecognized errors occur.
67+
"showOutput": "silent",
68+
69+
// The tsc compiler is started in watching mode
70+
"isWatching": true,
71+
5972
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
6073
"problemMatcher": "$tsc-watch"
6174
}

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Sample code illustrating the VS Code extension APIs.
44

55
* [Editor Decoration](/decorator-sample/README.md)
66
* [Virtual Documents](/contentprovider-sample/README.md)
7+
* [Language Provider](/languageprovider-sample/README.md)
78
* [Preview Html](/previewhtml-sample/README.md)
89
* [Vim](/vim-sample/README.md)
910
* [Integrated Terminal](/terminal-example/README.md)
@@ -12,5 +13,10 @@ Sample code illustrating the VS Code extension APIs.
1213
# How to run locally
1314

1415
* `git clone`
15-
* `npm run install-all`
16-
* run one of `npm run compile-decorator`, `npm run compile-previewhtml`, or `compile-contentprovider`
16+
* `npm install`
17+
* run one of
18+
* `npm run compile-decorator`,
19+
* `npm run compile-previewhtml`
20+
* `npm run compile-contentprovider`
21+
* `npm run compile-languageprovider`
22+
* launch the sample from the debug viewlet

build/postinstall.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
const cp = require('child_process');
7+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
8+
9+
function npmInstall(location) {
10+
const result = cp.spawnSync(npm, ['install'], {
11+
cwd: location ,
12+
stdio: 'inherit'
13+
});
14+
15+
if (result.error || result.status !== 0) {
16+
process.exit(1);
17+
}
18+
}
19+
20+
const samples = [
21+
'contentprovider-sample',
22+
'decorator-sample',
23+
'languageprovider-sample',
24+
'vim-sample',
25+
'terminal-example',
26+
'tree-explorer-sample'
27+
];
28+
29+
samples.forEach(npmInstall);

languageprovider-sample/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
out
2+
node_modules
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch Extension",
6+
"type": "extensionHost",
7+
"request": "launch",
8+
"runtimeExecutable": "${execPath}",
9+
"args": [
10+
"--extensionDevelopmentPath=${workspaceRoot}"
11+
],
12+
"stopOnEntry": false,
13+
"sourceMaps": true,
14+
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
15+
"preLaunchTask": "npm"
16+
},
17+
{
18+
"name": "Launch Extension Tests",
19+
"type": "extensionHost",
20+
"request": "launch",
21+
"runtimeExecutable": "${execPath}",
22+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/client/out/test" ],
23+
"stopOnEntry": false,
24+
"sourceMaps": true,
25+
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"],
26+
"preLaunchTask": "npm"
27+
},
28+
{
29+
"name": "Attach Language Server",
30+
"type": "node",
31+
"request": "attach",
32+
"port": 6004,
33+
"sourceMaps": true,
34+
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
35+
}
36+
37+
],
38+
"compounds": [
39+
{
40+
"name": "Launch Client & Server",
41+
"configurations": ["Launch Client", "Attach Language Server"]
42+
}
43+
]
44+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
{
3+
"version": "0.1.0",
4+
"command": "npm",
5+
"isShellCommand": true,
6+
"showOutput": "silent",
7+
"args": ["run", "watch"],
8+
"isWatching": true,
9+
"problemMatcher": "$tsc-watch"
10+
}

languageprovider-sample/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# README
2+
## This is the README for the "languageprovider-sample"
3+
-------------------
4+
5+
This folder contains a sample VS code extension that demonstrates an extension that runs a language server
6+
7+
The extension observes all 'plaintext' documents (documents from all editors not associated with a language)
8+
and uses the server to provide validation and completion proposals.
9+
10+
The code for the extension is in the 'client' folder. It uses the 'vscode-languageclient' node module to launch the language server.
11+
12+
The language server is located in the 'server' folder.
13+
14+
15+
# How to run locally
16+
* `npm install` to initialize the extension and the server
17+
* `npm run compile` to compile the extension and the server
18+
* 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.
19+
* create a file `foo.bar`, and type `typescript`. You should see a validation error.
20+
* set breakpoints in the server or the client
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* --------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
* ------------------------------------------------------------------------------------------ */
5+
'use strict';
6+
7+
import * as path from 'path';
8+
9+
import { workspace, Disposable, ExtensionContext } from 'vscode';
10+
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';
11+
12+
export function activate(context: ExtensionContext) {
13+
14+
// The server is implemented in node
15+
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'serverMain.js'));
16+
// The debug options for the server
17+
let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] };
18+
19+
// If the extension is launched in debug mode then the debug server options are used
20+
// Otherwise the run options are used
21+
let serverOptions: ServerOptions = {
22+
run : { module: serverModule, transport: TransportKind.ipc },
23+
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
24+
}
25+
26+
// Options to control the language client
27+
let clientOptions: LanguageClientOptions = {
28+
// Register the server for plain text documents
29+
documentSelector: ['plaintext'],
30+
synchronize: {
31+
// Synchronize the setting section 'languageServerExample' to the server
32+
configurationSection: 'languageServerExample',
33+
// Notify the server about file changes to '.clientrc files contain in the workspace
34+
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
35+
}
36+
}
37+
38+
// Create the language client and start the client.
39+
let disposable = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions).start();
40+
41+
// Push the disposable to the context's subscriptions so that the
42+
// client can be deactivated on extension deactivation
43+
context.subscriptions.push(disposable);
44+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"outDir": "./out",
6+
"skipLibCheck": true,
7+
"sourceMap": true,
8+
"lib": [
9+
"es5", "es2015.promise"
10+
]
11+
}
12+
}

languageprovider-sample/package.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "languageprovider-sample",
3+
"description": "Language provider extension that launches a language server",
4+
"author": "Microsoft Corporation",
5+
"license": "MIT",
6+
"version": "0.0.1",
7+
"publisher": "vscode",
8+
"engines": {
9+
"vscode": "^1.4.0"
10+
},
11+
"categories": [
12+
"Other"
13+
],
14+
"activationEvents": [
15+
"onLanguage:plaintext"
16+
],
17+
"main": "./client/out/clientMain",
18+
"contributes": {
19+
"configuration": {
20+
"type": "object",
21+
"title": "Example configuration",
22+
"properties": {
23+
"languageServerExample.maxNumberOfProblems": {
24+
"type": "number",
25+
"default": 100,
26+
"description": "Controls the maximum number of problems produced by the server."
27+
},
28+
"languageServerExample.trace.server": {
29+
"type": "string",
30+
"enum": [
31+
"off",
32+
"messages",
33+
"verbose"
34+
],
35+
"default": "off",
36+
"description": "Traces the communication between VSCode and the languageServerExample service."
37+
}
38+
}
39+
}
40+
},
41+
"scripts": {
42+
"vscode:prepublish": "tsc -p ./",
43+
"compile": "tsc -p ./client && cd server && npm run compile && cd ..",
44+
"update-vscode": "node ./node_modules/vscode/bin/install",
45+
"postinstall": "node ./node_modules/vscode/bin/install && cd server && npm install"
46+
},
47+
"devDependencies": {
48+
"@types/mocha": "^2.2.33",
49+
"@types/node": "^6.0.52",
50+
"typescript": "^2.1.4",
51+
"vscode": "^1.0.3"
52+
},
53+
"dependencies": {
54+
"vscode-languageclient": "^2.6.3"
55+
}
56+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "language-server-example",
3+
"description": "Example implementation of a language server in node.",
4+
"version": "0.0.1",
5+
"author": "Microsoft Corporation",
6+
"license": "MIT",
7+
"engines": {
8+
"node": "*"
9+
},
10+
"dependencies": {
11+
"vscode-languageserver": "^2.6.2"
12+
},
13+
"devDependencies": {
14+
"@types/node": "^6.0.52",
15+
"typescript": "^2.1.4"
16+
},
17+
"scripts": {
18+
"compile": "tsc -p .",
19+
"watch": "tsc --watch -p ."
20+
}
21+
}

0 commit comments

Comments
 (0)