Skip to content

Commit

Permalink
fix: json5 format setting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
minsgy committed Jun 7, 2024
1 parent 547a97f commit bb4d01f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/features/RouteEditPanel/utils/jsonAutoComplete.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { CompletionContext, CompletionResult } from "@codemirror/autocomplete"
import { jsonLanguage } from "@codemirror/lang-json"
import { syntaxTree } from "@codemirror/language"
import { faker } from "@faker-js/faker"
import { Extension } from "@uiw/react-codemirror"
import { json5Language } from "codemirror-json5"

export const jsonAutoComplete = () => {
return jsonLanguage.data.of({
export const jsonAutoComplete: () => Extension = () => {
return json5Language.data.of({
autocomplete: createJsonPropertyAutocomplete({
faker,
}),
})
}

function createJsonPropertyAutocomplete(
const createJsonPropertyAutocomplete = (
globalObject: Record<string, unknown>
): (context: CompletionContext) => CompletionResult | null {
): ((context: CompletionContext) => CompletionResult | null) => {
return (context) => {
let nodeBefore = syntaxTree(context.state).resolveInner(context.pos, -1)
if (
Expand All @@ -34,12 +35,12 @@ function createJsonPropertyAutocomplete(
}
}

function completeProperties(
const completeProperties = (
from: number,
variableName: string,
source: string,
globalObject: Record<string, any>
): CompletionResult | null {
): CompletionResult | null => {
const variables = source.split(".")
const lastIndex = variables.lastIndexOf(variableName)

Expand Down

0 comments on commit bb4d01f

Please sign in to comment.