Skip to content

Commit

Permalink
fix: issues with language and content being empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon committed Jan 28, 2024
1 parent ae6c596 commit cda2f85
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .helix/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
theme = "tokyonight_storm"

[editor.cursor-shape]
insert = "bar"

3 changes: 2 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const main = async () => {
triggerCharacters: ["{", "(", ")", "=", ">", " ", ",", ":", ".", "<", "/"]
},
textDocumentSync: {
change: 2,
change: 1,
openClose: true
}
}
})
Expand Down
6 changes: 5 additions & 1 deletion src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const extractCodeBlock = (filepath: string, text: string, language: string): str
}

const result = blocks[0];

const lines = result.replace(`// FILEPATH: ${filepath.replace('file://', '')}\n`, '').split('\n');
return lines.slice(1, lines.length - 1).join('\n') + "\n";
}
Expand Down Expand Up @@ -199,6 +199,8 @@ export const chat = async (request: string, contents: string, filepath: string,
throw new Error(`chat handler: ${config.handler} does not exist`)
}

language = language ?? "unknown"

try {
log("running chat handler:", config.handler)
return await chatHandlers[config.handler](request, contents, filepath, language)
Expand All @@ -214,6 +216,8 @@ export const completion = async (contents: any, language: string, suggestions =
throw new Error(`completion handler: ${config.handler} does not exist`)
}

language = language ?? "unknown"

try {
log("running completion handler:", config.handler)
return uniqueStringArray(await handlers[config.handler](contents, language, suggestions))
Expand Down
12 changes: 7 additions & 5 deletions src/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Service {
ctx.contents = request.params.textDocument.text
ctx.language = request.params.textDocument.languageId
ctx.contentVersion = 0
log("received didOpen", `language: ${ctx.language}`)
})

this.on(Event.Shutdown, () => {
Expand All @@ -97,12 +98,13 @@ class Service {
})

this.on(Event.DidChange, async ({ ctx, request }) => {
request.params.contentChanges.forEach((change) => {
this.positionalUpdate(change.text, change.range)
})

// request.params.contentChanges.forEach((change) => {
// this.positionalUpdate(change.text, change.range)
// })
this.contents = request.params.contentChanges[0].text
ctx.currentUri = request.params.textDocument.uri
ctx.contentVersion = request.params.textDocument.version
log("received didChange", `language: ${ctx.language}`, `contentVersion: ${ctx.contentVersion}`)
})
}

Expand All @@ -113,7 +115,7 @@ class Service {
}

positionalUpdate(text: string, range: Range) {
const lines = this.contents.split("\n")
const lines = this.contents?.split("\n")
const start = range.start.line
const end = range.end.line
const startLine = lines[start]
Expand Down

0 comments on commit cda2f85

Please sign in to comment.