Quantcast
Channel: Active questions tagged code-completion - Stack Overflow
Viewing all articles
Browse latest Browse all 74

How to enable/provide a vscode CompletionItemProvider when inside string literal?

$
0
0

I have a pretty basic vscode extension with a CompletionItemProvider. This works all well but when inside a string literal ("") the completion does not work anymore. I've found some older threads on the internet which state that it does work inside strings literals or double quotes and that they want to prohibit this behaviour. Those methodd to stop this behaviour did not provide a solution the other way around for me. For me it seems like vscode changed the default behaviour for the CompletionItemProvider as it is not working anymore like this.

Example text file:

<Input Name="Value1" Type="DIRECT"><Source>123456</Source></Input>

The completion works anywhere in the file except for the values of Name and Type. But I need it for the values of XML attributes which are always inside double quotes.

The completion provider:

import * as vscode from 'vscode';export function registerDefaultCompletion(context: vscode.ExtensionContext) {    context.subscriptions.push(        vscode.languages.registerCompletionItemProvider(            { pattern: '**/*' },            new DefaultCompletionItemProvider()        )    );}class DefaultCompletionItemProvider implements vscode.CompletionItemProvider {    provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): vscode.ProviderResult<vscode.CompletionItem[]> {        const completions: vscode.CompletionItem[] = [];        // values        completions.push(new vscode.CompletionItem('MULTIPLY_ALL', vscode.CompletionItemKind.Value));        completions.push(new vscode.CompletionItem('SUM_ALL', vscode.CompletionItemKind.Value));        completions.push(new vscode.CompletionItem('DIRECT', vscode.CompletionItemKind.Value));        completions.push(new vscode.CompletionItem('LOGIC_OR', vscode.CompletionItemKind.Value));        completions.push(new vscode.CompletionItem('LOGIC_AND', vscode.CompletionItemKind.Value));        completions.push(new vscode.CompletionItem('LOGIC_NOT', vscode.CompletionItemKind.Value));        return completions;    }}

Viewing all articles
Browse latest Browse all 74

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>