Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"type": "array",
"default": [],
"description": "Arguments to pass to the V language server."
},
"vls.inlayHints.enabled": {
"type": "boolean",
"default": true,
"description": "Enable or disable inlay hints for V files."
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-lan

let client: LanguageClient;

function isInlayHintsEnabled(): boolean {
return vscode.workspace.getConfiguration('vls').get<boolean>('inlayHints.enabled', true);
}

export async function activate(context: vscode.ExtensionContext) {
// Get the configuration for our server.
const config = vscode.workspace.getConfiguration('vls');
Expand Down Expand Up @@ -31,6 +35,14 @@ export async function activate(context: vscode.ExtensionContext) {
synchronize: {
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.v'),
},
middleware: {
provideInlayHints: async (document, range, token, next) => {
if (!isInlayHintsEnabled()) {
return [];
}
return next(document, range, token);
},
},
};

// Create the language client.
Expand All @@ -41,6 +53,29 @@ export async function activate(context: vscode.ExtensionContext) {
clientOptions
);

// A standalone provider whose sole purpose is to fire onDidChangeInlayHints so
// that VS Code immediately re-requests hints from all providers (including the
// LSP one above) whenever the toggle setting changes.
const inlayHintsEmitter = new vscode.EventEmitter<void>();
context.subscriptions.push(inlayHintsEmitter);
context.subscriptions.push(
vscode.languages.registerInlayHintsProvider(
{ scheme: 'file', language: 'v' },
{
onDidChangeInlayHints: inlayHintsEmitter.event,
provideInlayHints: () => [],
}
)
);

context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('vls.inlayHints.enabled')) {
inlayHintsEmitter.fire();
}
})
);

// Start the client. This will also launch the server.
vscode.window.showInformationMessage('V Language Server is starting.');
await client.start();
Expand Down