feat: test script auto completion for codemirror
This commit is contained in:
committed by
liyasthomas
parent
b9fc0175e7
commit
8d67a0d95f
30
helpers/editor/completion/testScript.ts
Normal file
30
helpers/editor/completion/testScript.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { convertIndexToLineCh } from "../utils"
|
||||||
|
import { Completer, CompletionEntry } from "."
|
||||||
|
import { getTestScriptCompletions } from "~/helpers/tern"
|
||||||
|
|
||||||
|
export const completer: Completer = async (text, completePos) => {
|
||||||
|
const results = await getTestScriptCompletions(
|
||||||
|
text,
|
||||||
|
completePos.line,
|
||||||
|
completePos.ch
|
||||||
|
)
|
||||||
|
|
||||||
|
const start = convertIndexToLineCh(text, results.start)
|
||||||
|
const end = convertIndexToLineCh(text, results.end)
|
||||||
|
|
||||||
|
const completions = results.completions.map((completion: any, i: number) => {
|
||||||
|
return <CompletionEntry>{
|
||||||
|
text: completion.name,
|
||||||
|
meta: completion.isKeyword ? "keyword" : completion.type,
|
||||||
|
score: results.completions.length - i,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
completions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default completer
|
||||||
Reference in New Issue
Block a user