NOTE: This is heavily based on lsp-sample from vscode-extension-samples with the goal of removing example-specific code to ease starting a new Language Server.
This project aims to provide a starting point for developing a self-contained Language Server Extension for VS Code using TypeScript.
"Self-contained" in this context means that this extension bundles its own language server code rather than wrapping an existing language server executable.
As an MVP, this omits
- linting
- testing
- behavior in the language server itself (besides connecting and listening to document changes)
- Clone this repo
- Replace items in
package.json
markedREPLACE_ME
with text related to your extension - Do the same for
client/package.json
andserver/package.json
- Do the same in
client/src/extension.ts
- Run
npm install
from the repo root.
To make it easy to get started, this language server will run on every file type by default. To target specific languages, change
package.json
's activationEvents
to something like
"activationEvents": [
"onLanguage:plaintext"
],
And change the documentSelector
in client/src/extension.ts
to replace the *
(e.g.)
documentSelector: [{ scheme: "file", language: "plaintext" }],
To help verify everything is working properly, we've included the following code in server.ts
after the onInitialize
function:
documents.onDidChangeContent((change) => {
connection.window.showInformationMessage(
"onDidChangeContent: " + change.document.uri
);
});
From the root directory of this project, run code .
Then in VS Code
-
Build the extension (both client and server) with
⌘+shift+B
(orctrl+shift+B
on windows) -
Open the Run and Debug view and press "Launch Client" (or press
F5
). This will open a[Extension Development Host]
VS Code window. -
Opening or editing a file in that window should show an information message in VS Code like you see below.
-
Edits made to your
server.ts
will be rebuilt immediately but you'll need to "Launch Client" again (⌘-shift-F5
) from the primary VS Code window to see the impact of your changes.
Debugging instructions can be found here
Read the full Publishing Extensions doc for the full details.
Note that you can package and distribute a standalone .vsix
file without publishing it to the marketplace by following these instructions.
.
├── .vscode
│ ├── launch.json // Tells VS Code how to launch our extension
│ └── tasks.json // Tells VS Code how to build our extension
├── LICENSE
├── README.md
├── client
│ ├── package-lock.json // Client dependencies lock file
│ ├── package.json // Client manifest
│ ├── src
│ │ └── extension.ts // Code to tell VS Code how to run our language server
│ └── tsconfig.json // TypeScript config for the client
├── package-lock.json // Top-level Dependencies lock file
├── package.json // Top-level manifest
├── server
│ ├── package-lock.json // Server dependencies lock file
│ ├── package.json // Server manifest
│ ├── src
│ │ └── server.ts // Language server code
│ └── tsconfig.json // TypeScript config for the client
└── tsconfig.json // Top-level TypeScript config