-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(typescript): split into multiple ServicePlugins (#83)
- Loading branch information
1 parent
411857c
commit 3f9ccc6
Showing
39 changed files
with
2,189 additions
and
2,630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type * as vscode from '@volar/language-service'; | ||
import * as nls from 'vscode-nls'; | ||
import { isTsDocument } from './lib/shared'; | ||
|
||
const localize = nls.loadMessageBundle(); // TODO: not working | ||
|
||
interface Directive { | ||
readonly value: string; | ||
readonly description: string; | ||
} | ||
|
||
const directives: Directive[] = [ | ||
{ | ||
value: '@ts-check', | ||
description: localize( | ||
'ts-check', | ||
"Enables semantic checking in a JavaScript file. Must be at the top of a file.") | ||
}, { | ||
value: '@ts-nocheck', | ||
description: localize( | ||
'ts-nocheck', | ||
"Disables semantic checking in a JavaScript file. Must be at the top of a file.") | ||
}, { | ||
value: '@ts-ignore', | ||
description: localize( | ||
'ts-ignore', | ||
"Suppresses @ts-check errors on the next line of a file.") | ||
}, { | ||
value: '@ts-expect-error', | ||
description: localize( | ||
'ts-expect-error', | ||
"Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.") | ||
} | ||
]; | ||
|
||
export function create(): vscode.ServicePlugin { | ||
return { | ||
name: 'typescript-directive-comment', | ||
triggerCharacters: ['@'], | ||
create(): vscode.ServicePluginInstance { | ||
|
||
return { | ||
|
||
provideCompletionItems(document, position) { | ||
|
||
if (!isTsDocument(document)) | ||
return; | ||
|
||
const prefix = document.getText({ | ||
start: { line: position.line, character: 0 }, | ||
end: position, | ||
}); | ||
const match = prefix.match(/^\s*\/\/+\s?(@[a-zA-Z\-]*)?$/); | ||
if (match) { | ||
|
||
const items = directives.map(directive => { | ||
|
||
const item: vscode.CompletionItem = { label: directive.value }; | ||
item.insertTextFormat = 2 satisfies typeof vscode.InsertTextFormat.Snippet; | ||
item.detail = directive.description; | ||
const range: vscode.Range = { | ||
start: { | ||
line: position.line, | ||
character: Math.max(0, position.character - (match[1] ? match[1].length : 0)), | ||
}, | ||
end: position, | ||
}; | ||
item.textEdit = { | ||
range, | ||
newText: directive.value, | ||
}; | ||
|
||
return item; | ||
}); | ||
|
||
return { | ||
isIncomplete: false, | ||
items, | ||
}; | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
} |
62 changes: 37 additions & 25 deletions
62
...escript/lib/features/completions/jsDoc.ts → packages/typescript/docCommentTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.