refactor: pass current token position to auto completers on codemirror
This commit is contained in:
committed by
liyasthomas
parent
8d67a0d95f
commit
d6e3bd09b4
@@ -27,6 +27,7 @@ import "codemirror/addon/dialog/dialog"
|
|||||||
import { watch, onMounted, ref, Ref, useContext } from "@nuxtjs/composition-api"
|
import { watch, onMounted, ref, Ref, useContext } from "@nuxtjs/composition-api"
|
||||||
import { LinterDefinition } from "./linting/linter"
|
import { LinterDefinition } from "./linting/linter"
|
||||||
import { Completer } from "./completion"
|
import { Completer } from "./completion"
|
||||||
|
import { convertIndexToLineCh } from "./utils"
|
||||||
|
|
||||||
type CodeMirrorOptions = {
|
type CodeMirrorOptions = {
|
||||||
extendedEditorConfig: Omit<CodeMirror.EditorConfiguration, "value">
|
extendedEditorConfig: Omit<CodeMirror.EditorConfiguration, "value">
|
||||||
@@ -88,10 +89,14 @@ export function useCodemirror(
|
|||||||
const pos = editor.getCursor()
|
const pos = editor.getCursor()
|
||||||
const text = editor.getValue()
|
const text = editor.getValue()
|
||||||
|
|
||||||
const result = await options.completer!(text, pos)
|
const token = editor.getTokenAt(pos)
|
||||||
|
|
||||||
console.log("complete!")
|
const result = await options.completer!(text, pos, {
|
||||||
console.log(result)
|
start: convertIndexToLineCh(text, token.start),
|
||||||
|
end: convertIndexToLineCh(text, token.end),
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!result) return null
|
||||||
|
|
||||||
return <CodeMirror.Hints>{
|
return <CodeMirror.Hints>{
|
||||||
from: result.start,
|
from: result.start,
|
||||||
|
|||||||
@@ -29,5 +29,9 @@ export type Completer = (
|
|||||||
/**
|
/**
|
||||||
* Position where the completer is fired
|
* Position where the completer is fired
|
||||||
*/
|
*/
|
||||||
completePos: { line: number; ch: number }
|
completePos: { line: number; ch: number },
|
||||||
) => Promise<CompleterResult>
|
completeTokenLocation: {
|
||||||
|
start: { line: number; ch: number }
|
||||||
|
end: { line: number; ch: number }
|
||||||
|
}
|
||||||
|
) => Promise<CompleterResult | null>
|
||||||
|
|||||||
Reference in New Issue
Block a user