fix: autocompletion position messing up
This commit is contained in:
@@ -28,7 +28,6 @@ import "codemirror/addon/selection/active-line"
|
||||
import { watch, onMounted, ref, Ref, useContext } from "@nuxtjs/composition-api"
|
||||
import { LinterDefinition } from "./linting/linter"
|
||||
import { Completer } from "./completion"
|
||||
import { convertIndexToLineCh } from "./utils"
|
||||
|
||||
type CodeMirrorOptions = {
|
||||
extendedEditorConfig: Omit<CodeMirror.EditorConfiguration, "value">
|
||||
@@ -99,16 +98,13 @@ export function useCodemirror(
|
||||
|
||||
const token = editor.getTokenAt(pos)
|
||||
|
||||
const result = await options.completer!(text, pos, {
|
||||
start: convertIndexToLineCh(text, token.start),
|
||||
end: convertIndexToLineCh(text, token.end),
|
||||
})
|
||||
const result = await options.completer!(text, pos)
|
||||
|
||||
if (!result) return null
|
||||
|
||||
return <CodeMirror.Hints>{
|
||||
from: result.start,
|
||||
to: result.end,
|
||||
from: { line: pos.line, ch: token.start },
|
||||
to: { line: pos.line, ch: token.end },
|
||||
list: result.completions
|
||||
.sort((a, b) => a.score - b.score)
|
||||
.map((x) => x.text),
|
||||
|
||||
@@ -4,7 +4,7 @@ import { getAutocompleteSuggestions } from "graphql-language-service-interface"
|
||||
import { Completer, CompleterResult, CompletionEntry } from "."
|
||||
|
||||
const completer: (schemaRef: Ref<GraphQLSchema | null>) => Completer =
|
||||
(schemaRef: Ref<GraphQLSchema | null>) => (text, completePos, tokenPos) => {
|
||||
(schemaRef: Ref<GraphQLSchema | null>) => (text, completePos) => {
|
||||
if (!schemaRef.value) return Promise.resolve(null)
|
||||
|
||||
const completions = getAutocompleteSuggestions(schemaRef.value, text, {
|
||||
@@ -13,8 +13,6 @@ const completer: (schemaRef: Ref<GraphQLSchema | null>) => Completer =
|
||||
} as any)
|
||||
|
||||
return Promise.resolve(<CompleterResult>{
|
||||
start: tokenPos.start,
|
||||
end: tokenPos.end,
|
||||
completions: completions.map(
|
||||
(x, i) =>
|
||||
<CompletionEntry>{
|
||||
|
||||
@@ -9,16 +9,6 @@ export type CompleterResult = {
|
||||
* List of completions to display
|
||||
*/
|
||||
completions: CompletionEntry[]
|
||||
/**
|
||||
* Start of the completion position
|
||||
* (on completion the start..end region is replaced)
|
||||
*/
|
||||
start: { line: number; ch: number }
|
||||
/**
|
||||
* End of the completion position
|
||||
* (on completion the start..end region is replaced)
|
||||
*/
|
||||
end: { line: number; ch: number }
|
||||
}
|
||||
|
||||
export type Completer = (
|
||||
@@ -29,9 +19,5 @@ export type Completer = (
|
||||
/**
|
||||
* Position where the completer is fired
|
||||
*/
|
||||
completePos: { line: number; ch: number },
|
||||
completeTokenLocation: {
|
||||
start: { line: number; ch: number }
|
||||
end: { line: number; ch: number }
|
||||
}
|
||||
completePos: { line: number; ch: number }
|
||||
) => Promise<CompleterResult | null>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { convertIndexToLineCh } from "../utils"
|
||||
import { Completer, CompletionEntry } from "."
|
||||
import { getPreRequestScriptCompletions } from "~/helpers/tern"
|
||||
|
||||
@@ -9,9 +8,6 @@ const completer: Completer = async (text, completePos) => {
|
||||
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,
|
||||
@@ -21,8 +17,6 @@ const completer: Completer = async (text, completePos) => {
|
||||
})
|
||||
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
completions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { convertIndexToLineCh } from "../utils"
|
||||
import { Completer, CompletionEntry } from "."
|
||||
import { getTestScriptCompletions } from "~/helpers/tern"
|
||||
|
||||
@@ -9,9 +8,6 @@ export const completer: Completer = async (text, completePos) => {
|
||||
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,
|
||||
@@ -21,8 +17,6 @@ export const completer: Completer = async (text, completePos) => {
|
||||
})
|
||||
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
completions,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user