-
-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support auto-complete for directive comments
ref #3215
- Loading branch information
1 parent
cefbaff
commit 7a98593
Showing
2 changed files
with
65 additions
and
0 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
63 changes: 63 additions & 0 deletions
63
packages/vue-language-service/src/plugins/vue-directive-comments.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { CompletionItem, Service } from '@volar/language-service'; | ||
|
||
const cmds = [ | ||
'vue-ignore', | ||
'vue-skip', | ||
'vue-expect-error', | ||
]; | ||
|
||
const plugin: Service = (): ReturnType<Service> => { | ||
|
||
return { | ||
|
||
triggerCharacters: ['@'], | ||
|
||
provideCompletionItems(document, position) { | ||
|
||
if (document.languageId !== 'html') | ||
return; | ||
|
||
const line = document.getText({ start: { line: position.line, character: 0 }, end: position }); | ||
const cmdStart = line.match(/<!--\s+@/); | ||
if (!cmdStart) | ||
return; | ||
|
||
const startIndex = cmdStart.index! + cmdStart[0].length; | ||
const remainText = line.substring(startIndex); | ||
const result: CompletionItem[] = []; | ||
|
||
for (const cmd of cmds) { | ||
let match = true; | ||
for (let i = 0; i < remainText.length; i++) { | ||
if (remainText[i] !== cmd[i]) { | ||
console.log(JSON.stringify(remainText[i]), JSON.stringify(cmd[i])); | ||
match = false; | ||
break; | ||
} | ||
} | ||
if (match) { | ||
result.push({ | ||
label: '@' + cmd, | ||
textEdit: { | ||
range: { | ||
start: { | ||
line: position.line, | ||
character: startIndex - 1, | ||
}, | ||
end: position, | ||
}, | ||
newText: '@' + cmd, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
return { | ||
isIncomplete: false, | ||
items: result, | ||
}; | ||
}, | ||
}; | ||
}; | ||
|
||
export default () => plugin; |