Skip to content

Commit

Permalink
LSP: Add support for Suite/Module constants within Go To Definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jansul committed Jul 21, 2023
1 parent e94f3c8 commit 0f1f65b
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 1 deletion.
55 changes: 55 additions & 0 deletions spec/language_server/definition/location/variable_module_constant
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Test {
const TITLE = "title"

fun title : String {
TITLE
}
}
------------------------------------------------------------------file test.mint
{
"id": 0,
"method": "initialize",
"params": {
"capabilities": {
"textDocument": {
"definition": {
"linkSupport": false
}
}
}
}
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"id": 1,
"params": {
"textDocument": {
"uri": "file://#{root_path}/test.mint"
},
"position": {
"line": 4,
"character": 4
}
},
"method": "textDocument/definition"
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"result": {
"range": {
"start": {
"line": 1,
"character": 8
},
"end": {
"line": 1,
"character": 13
}
},
"uri": "file://#{root_path}/test.mint"
},
"id": 1
}
------------------------------------------------------------------------response
55 changes: 55 additions & 0 deletions spec/language_server/definition/location/variable_suite_constant
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
suite "Test" {
const TITLE = "title"

test "it has a constant" {
TITLE == "title"
}
}
------------------------------------------------------------------file test.mint
{
"id": 0,
"method": "initialize",
"params": {
"capabilities": {
"textDocument": {
"definition": {
"linkSupport": false
}
}
}
}
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"id": 1,
"params": {
"textDocument": {
"uri": "file://#{root_path}/test.mint"
},
"position": {
"line": 4,
"character": 4
}
},
"method": "textDocument/definition"
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"result": {
"range": {
"start": {
"line": 1,
"character": 8
},
"end": {
"line": 1,
"character": 13
}
},
"uri": "file://#{root_path}/test.mint"
},
"id": 1
}
------------------------------------------------------------------------response
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module Test {
const TITLE = "title"

fun title : String {
TITLE
}
}
------------------------------------------------------------------file test.mint
{
"id": 0,
"method": "initialize",
"params": {
"capabilities": {
"textDocument": {
"definition": {
"linkSupport": true
}
}
}
}
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"id": 1,
"params": {
"textDocument": {
"uri": "file://#{root_path}/test.mint"
},
"position": {
"line": 4,
"character": 4
}
},
"method": "textDocument/definition"
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"result": {
"originSelectionRange": {
"start": {
"line": 4,
"character": 4
},
"end": {
"line": 4,
"character": 9
}
},
"targetUri": "file://#{root_path}/test.mint",
"targetRange": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 23
}
},
"targetSelectionRange": {
"start": {
"line": 1,
"character": 8
},
"end": {
"line": 1,
"character": 13
}
}
},
"id": 1
}
------------------------------------------------------------------------response
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
suite "Test" {
const TITLE = "title"

test "it has a constant" {
TITLE == "title"
}
}
------------------------------------------------------------------file test.mint
{
"id": 0,
"method": "initialize",
"params": {
"capabilities": {
"textDocument": {
"definition": {
"linkSupport": true
}
}
}
}
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"id": 1,
"params": {
"textDocument": {
"uri": "file://#{root_path}/test.mint"
},
"position": {
"line": 4,
"character": 4
}
},
"method": "textDocument/definition"
}
-------------------------------------------------------------------------request
{
"jsonrpc": "2.0",
"result": {
"originSelectionRange": {
"start": {
"line": 4,
"character": 4
},
"end": {
"line": 4,
"character": 9
}
},
"targetUri": "file://#{root_path}/test.mint",
"targetRange": {
"start": {
"line": 1,
"character": 2
},
"end": {
"line": 1,
"character": 23
}
},
"targetSelectionRange": {
"start": {
"line": 1,
"character": 8
},
"end": {
"line": 1,
"character": 13
}
}
},
"id": 1
}
------------------------------------------------------------------------response
5 changes: 4 additions & 1 deletion src/ls/definition/enum_id.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module Mint
if name.nil?
stack.each do |parent|
case parent
when Ast::Component, Ast::Store
when Ast::Component,
Ast::Store,
Ast::Suite,
Ast::Module
parent.constants.each do |constant|
if node.option.value == constant.name.value
return location_link server, node.option, constant.name, constant
Expand Down

0 comments on commit 0f1f65b

Please sign in to comment.