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 { 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">
|
||||||
@@ -99,16 +98,13 @@ export function useCodemirror(
|
|||||||
|
|
||||||
const token = editor.getTokenAt(pos)
|
const token = editor.getTokenAt(pos)
|
||||||
|
|
||||||
const result = await options.completer!(text, pos, {
|
const result = await options.completer!(text, pos)
|
||||||
start: convertIndexToLineCh(text, token.start),
|
|
||||||
end: convertIndexToLineCh(text, token.end),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!result) return null
|
if (!result) return null
|
||||||
|
|
||||||
return <CodeMirror.Hints>{
|
return <CodeMirror.Hints>{
|
||||||
from: result.start,
|
from: { line: pos.line, ch: token.start },
|
||||||
to: result.end,
|
to: { line: pos.line, ch: token.end },
|
||||||
list: result.completions
|
list: result.completions
|
||||||
.sort((a, b) => a.score - b.score)
|
.sort((a, b) => a.score - b.score)
|
||||||
.map((x) => x.text),
|
.map((x) => x.text),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { getAutocompleteSuggestions } from "graphql-language-service-interface"
|
|||||||
import { Completer, CompleterResult, CompletionEntry } from "."
|
import { Completer, CompleterResult, CompletionEntry } from "."
|
||||||
|
|
||||||
const completer: (schemaRef: Ref<GraphQLSchema | null>) => Completer =
|
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)
|
if (!schemaRef.value) return Promise.resolve(null)
|
||||||
|
|
||||||
const completions = getAutocompleteSuggestions(schemaRef.value, text, {
|
const completions = getAutocompleteSuggestions(schemaRef.value, text, {
|
||||||
@@ -13,8 +13,6 @@ const completer: (schemaRef: Ref<GraphQLSchema | null>) => Completer =
|
|||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
return Promise.resolve(<CompleterResult>{
|
return Promise.resolve(<CompleterResult>{
|
||||||
start: tokenPos.start,
|
|
||||||
end: tokenPos.end,
|
|
||||||
completions: completions.map(
|
completions: completions.map(
|
||||||
(x, i) =>
|
(x, i) =>
|
||||||
<CompletionEntry>{
|
<CompletionEntry>{
|
||||||
|
|||||||
@@ -9,16 +9,6 @@ export type CompleterResult = {
|
|||||||
* List of completions to display
|
* List of completions to display
|
||||||
*/
|
*/
|
||||||
completions: CompletionEntry[]
|
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 = (
|
export type Completer = (
|
||||||
@@ -29,9 +19,5 @@ 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 }
|
||||||
completeTokenLocation: {
|
|
||||||
start: { line: number; ch: number }
|
|
||||||
end: { line: number; ch: number }
|
|
||||||
}
|
|
||||||
) => Promise<CompleterResult | null>
|
) => Promise<CompleterResult | null>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { convertIndexToLineCh } from "../utils"
|
|
||||||
import { Completer, CompletionEntry } from "."
|
import { Completer, CompletionEntry } from "."
|
||||||
import { getPreRequestScriptCompletions } from "~/helpers/tern"
|
import { getPreRequestScriptCompletions } from "~/helpers/tern"
|
||||||
|
|
||||||
@@ -9,9 +8,6 @@ const completer: Completer = async (text, completePos) => {
|
|||||||
completePos.ch
|
completePos.ch
|
||||||
)
|
)
|
||||||
|
|
||||||
const start = convertIndexToLineCh(text, results.start)
|
|
||||||
const end = convertIndexToLineCh(text, results.end)
|
|
||||||
|
|
||||||
const completions = results.completions.map((completion: any, i: number) => {
|
const completions = results.completions.map((completion: any, i: number) => {
|
||||||
return <CompletionEntry>{
|
return <CompletionEntry>{
|
||||||
text: completion.name,
|
text: completion.name,
|
||||||
@@ -21,8 +17,6 @@ const completer: Completer = async (text, completePos) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start,
|
|
||||||
end,
|
|
||||||
completions,
|
completions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { convertIndexToLineCh } from "../utils"
|
|
||||||
import { Completer, CompletionEntry } from "."
|
import { Completer, CompletionEntry } from "."
|
||||||
import { getTestScriptCompletions } from "~/helpers/tern"
|
import { getTestScriptCompletions } from "~/helpers/tern"
|
||||||
|
|
||||||
@@ -9,9 +8,6 @@ export const completer: Completer = async (text, completePos) => {
|
|||||||
completePos.ch
|
completePos.ch
|
||||||
)
|
)
|
||||||
|
|
||||||
const start = convertIndexToLineCh(text, results.start)
|
|
||||||
const end = convertIndexToLineCh(text, results.end)
|
|
||||||
|
|
||||||
const completions = results.completions.map((completion: any, i: number) => {
|
const completions = results.completions.map((completion: any, i: number) => {
|
||||||
return <CompletionEntry>{
|
return <CompletionEntry>{
|
||||||
text: completion.name,
|
text: completion.name,
|
||||||
@@ -21,8 +17,6 @@ export const completer: Completer = async (text, completePos) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start,
|
|
||||||
end,
|
|
||||||
completions,
|
completions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user