Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/content/docs/reference/services.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ These methods are called by the Volar language server when it needs to perform a
```ts title="service.ts"
export const service = {
name: 'my-service', // The name of the service, this is used to identify the service in the logs and in Volar Labs
create(context): ServicePluginInstance {
create(context): LanguageServicePluginInstance {
return {
provideHover(document, position, token) {
// Implement hover support here
},
// More methods...
};
},
} satisfies ServicePlugin;
} satisfies LanguageServicePlugin;
```

## Using a service
Expand All @@ -37,7 +37,7 @@ When initializing the language server, the list of services to use is passed as
import {
createConnection,
createServer,
createSimpleProjectProviderFactory,
createSimpleProject,
} from "@volar/language-server/node";
import { service } from "./service";

Expand All @@ -46,13 +46,12 @@ const server = createServer(connection);

connection.listen();

function getLanguageServicePlugins() {
return [service];
}

connection.onInitialize((params) => {
return server.initialize(params, createSimpleProjectProviderFactory(), {
// ...
getServicePlugins() {
return [service];
},
});
return server.initialize(params, createSimpleProject(), getLanguageServicePlugins());
});

connection.onInitialized(() => {
Expand All @@ -79,7 +78,7 @@ import { CompletionItemKind } from '@volar/language-server';

export const service = {
name: 'my-service',
create(context): ServicePluginInstance {
create(context): LanguageServicePluginInstance {
return {
provideCompletionItems(document, position, token) {
return {
Expand All @@ -100,7 +99,7 @@ export const service = {
},
};
},
} satisfies ServicePlugin;
} satisfies LanguageServicePlugin;
```

### `resolveCompletionItem`
Expand Down