Skip to content

Commit

Permalink
Got go-to definition request/response working
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Feb 8, 2024
1 parent 4be2e42 commit e3a0c65
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main.adept
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func main(argc int, argv **ubyte) int {
changeDocument(message)
} elif message.method == "textDocument/completion" {
completion(message)
} elif message.method == "textDocument/definition" {
definition(message)
}
}

Expand All @@ -72,6 +74,7 @@ define TEXT_DOCUMENT_SYNC_KIND_FULL = 1.0
func initialize(id JSON) {
capabilities <<String, JSON> AsymmetricPair> InitializerList = {
AsymmetricPair("hoverProvider", JSON(true)),
AsymmetricPair("definitionProvider", JSON(true)),
AsymmetricPair("textDocumentSync", JSON({
AsymmetricPair("openClose", JSON(true)),
AsymmetricPair("change", JSON(TEXT_DOCUMENT_SYNC_KIND_FULL))
Expand Down Expand Up @@ -282,3 +285,43 @@ func completion(message *Message) {

lsp\writeMessage(response)
}

func definition(message *Message) {
id JSON = message.id
text_document JSON = message.params.field("textDocument")
position Position = Position(message.params.field("position"))
uri String = text_document.field("uri").string().orElse("")

result JSON = JSON\null()
document *Document = adeptls\documents.documents.getPointer(uri)

if document {
text_index <usize> Optional = getTextIndex(document.text_content, position)

if text_index.has {
result = JSON\array()

result.add(JSON({
AsymmetricPair("uri", JSON(uri.clone())),
AsymmetricPair("range", JSON({
AsymmetricPair("start", JSON({
AsymmetricPair("line", JSON(0)),
AsymmetricPair("character", JSON(0)),
})),
AsymmetricPair("end", JSON({
AsymmetricPair("line", JSON(0)),
AsymmetricPair("character", JSON(0)),
})),
}))
}))
}
}

response JSON = JSON({
AsymmetricPair("jsonrpc", JSON("2.0")),
AsymmetricPair("id", id.toOwned()),
AsymmetricPair("result", result.toOwned())
})

lsp\writeMessage(response)
}

0 comments on commit e3a0c65

Please sign in to comment.