From 0f1f65bf253833d316e6cae9287c7390e3a5c122 Mon Sep 17 00:00:00 2001 From: Jon Sully Date: Fri, 21 Jul 2023 17:47:11 +0100 Subject: [PATCH] LSP: Add support for Suite/Module constants within Go To Definition --- .../location/variable_module_constant | 55 ++++++++++++++ .../location/variable_suite_constant | 55 ++++++++++++++ .../location_link/variable_module_constant | 75 +++++++++++++++++++ .../location_link/variable_suite_constant | 75 +++++++++++++++++++ src/ls/definition/enum_id.cr | 5 +- 5 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 spec/language_server/definition/location/variable_module_constant create mode 100644 spec/language_server/definition/location/variable_suite_constant create mode 100644 spec/language_server/definition/location_link/variable_module_constant create mode 100644 spec/language_server/definition/location_link/variable_suite_constant diff --git a/spec/language_server/definition/location/variable_module_constant b/spec/language_server/definition/location/variable_module_constant new file mode 100644 index 000000000..0a6d47701 --- /dev/null +++ b/spec/language_server/definition/location/variable_module_constant @@ -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 diff --git a/spec/language_server/definition/location/variable_suite_constant b/spec/language_server/definition/location/variable_suite_constant new file mode 100644 index 000000000..26b459d6b --- /dev/null +++ b/spec/language_server/definition/location/variable_suite_constant @@ -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 diff --git a/spec/language_server/definition/location_link/variable_module_constant b/spec/language_server/definition/location_link/variable_module_constant new file mode 100644 index 000000000..f9adb0c1b --- /dev/null +++ b/spec/language_server/definition/location_link/variable_module_constant @@ -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 diff --git a/spec/language_server/definition/location_link/variable_suite_constant b/spec/language_server/definition/location_link/variable_suite_constant new file mode 100644 index 000000000..cdc6aa815 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_suite_constant @@ -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 diff --git a/src/ls/definition/enum_id.cr b/src/ls/definition/enum_id.cr index 8ce0d84c1..958d3d24e 100644 --- a/src/ls/definition/enum_id.cr +++ b/src/ls/definition/enum_id.cr @@ -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