추가 코드 완성으로 JSON 편집을 향상시켜야하는 VSCode 확장을 개발 중입니다. 그러므로 나는 (네 더미 제안을 추가 foo
, foo1
, foo2
, foo3
) 테스트를 시작합니다. JSON 키 뒤에 콜론을 입력하면 예상대로 작동합니다.
또한 빈 개체에서 완료를 트리거하면 원하는대로 작동합니다 (다른 확장 프로그램의 제안 포함).
그러나 큰 따옴표 내에서 완료를 트리거하면 (텍스트 포함 여부에 관계없이) 내 제안이 누락되었습니다.
When I set a breakpoint in my CompletionItemProvider
execution pauses as expected in both cases. So it is called correctly and it returns my suggestions for sure. I looked in existing JSON editor extensions (even VSCodes default one) to get advice how to implement it correctly and to see if the default JSON extension maybe overwrites all suggestions within double quotes (even though that would break the whole extensibility idea in my opinion) but couldn't find anything.
To reproduce it is enough to scaffold an empty extension as described here.
Here is my extension.ts:
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
class OpenApiCompletionItemProvider implements vscode.CompletionItemProvider {
public provideCompletionItems(
document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken):
Thenable<vscode.CompletionItem[]> {
return Promise.resolve([
new vscode.CompletionItem('foo', vscode.CompletionItemKind.Class),
new vscode.CompletionItem('foo1', vscode.CompletionItemKind.Property),
new vscode.CompletionItem('foo2', vscode.CompletionItemKind.Interface),
new vscode.CompletionItem('foo3', vscode.CompletionItemKind.Class),
]);
}
}
export function activate(ctx: vscode.ExtensionContext): void {
ctx.subscriptions.push(
vscode.languages.registerCompletionItemProvider(
{ pattern: '**/*.openapi.json' },
new OpenApiCompletionItemProvider(),
':',
'"'
)
);
}
// this method is called when your extension is deactivated
export function deactivate() { }
The starting quote "
is part of what VSCode considers the current "word". Consequently, the completion items you return don't match the current filter string "
and are not displayed.
삽입 텍스트에 전체 단어 (따옴표 포함)를 포함하여이 문제를 해결할 수 있습니다.
new vscode.CompletionItem('"foo"', vscode.CompletionItemKind.Class)
( label
문자열을 동일 하게 유지하고 insertText
완료 팝업에 따옴표가 표시되지 않도록 하려면 사용 )
또는 range
그에 따라 조정할 수 있습니다 .
var item = new vscode.CompletionItem('foo', vscode.CompletionItemKind.Class);
item.range = new vscode.Range(position, position);
참고 : document.getWordRangeAtPosition()
유용 할 수 있습니다 . 여기 에서 JSON의 "단어"정의를 찾을 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다