-
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.
- Loading branch information
1 parent
f2ab701
commit 05f20db
Showing
17 changed files
with
883 additions
and
915 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
export * from '@volar/typescript'; | ||
export * from './lib/semantic'; | ||
export * from './lib/syntactic'; | ||
export { Provide } from './lib/plugins/semantic'; | ||
|
||
import { create as createDirectiveCommentServicePlugin } from './lib/plugins/directiveComment'; | ||
import { create as createDocCommentTemplateServicePlugin } from './lib/plugins/docCommentTemplate'; | ||
import { create as createSemanticServicePlugin } from './lib/plugins/semantic'; | ||
import { create as createSyntacticServicePlugin } from './lib/plugins/syntactic'; | ||
|
||
export function create(ts: typeof import('typescript')) { | ||
return [ | ||
createSemanticServicePlugin(ts), | ||
createSyntacticServicePlugin(ts), | ||
createDocCommentTemplateServicePlugin(ts), | ||
createDirectiveCommentServicePlugin(), | ||
]; | ||
} |
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 '../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, | ||
}; | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
} |
61 changes: 39 additions & 22 deletions
61
...ib/semantic/features/completions/jsDoc.ts → ...escript/lib/plugins/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.