From 2ee1c70737701f243c0f772659f985ea432a0e17 Mon Sep 17 00:00:00 2001 From: jansul Date: Tue, 8 Aug 2023 09:46:14 +0100 Subject: [PATCH] LSP: Add Go To Definition support for `Ast::ModuleAccess` (#623) --- .../location/module_access_component_constant | 63 +++++++++ .../location/module_access_component_function | 61 +++++++++ .../location/module_access_component_gets | 65 ++++++++++ .../location/module_access_component_name | 61 +++++++++ .../location/module_access_component_state | 63 +++++++++ .../location/module_access_module_constant | 59 +++++++++ .../location/module_access_module_function | 61 +++++++++ .../location/module_access_module_multiple | 82 ++++++++++++ .../location/module_access_module_name | 61 +++++++++ .../location/module_access_module_name_shared | 68 ++++++++++ .../location/module_access_store_constant | 59 +++++++++ .../location/module_access_store_function | 61 +++++++++ .../location/module_access_store_gets | 61 +++++++++ .../location/module_access_store_name | 61 +++++++++ .../location/module_access_store_state | 59 +++++++++ .../definition/location/type_enum | 2 +- .../definition/location/type_record | 2 +- .../module_access_component_constant | 83 ++++++++++++ .../module_access_component_function | 81 ++++++++++++ .../module_access_component_gets | 85 ++++++++++++ .../module_access_component_name | 81 ++++++++++++ .../module_access_component_state | 83 ++++++++++++ .../module_access_module_constant | 79 ++++++++++++ .../module_access_module_function | 81 ++++++++++++ .../module_access_module_multiple | 122 ++++++++++++++++++ .../location_link/module_access_module_name | 81 ++++++++++++ .../module_access_module_name_shared | 88 +++++++++++++ .../module_access_store_constant | 79 ++++++++++++ .../module_access_store_function | 81 ++++++++++++ .../location_link/module_access_store_gets | 81 ++++++++++++ .../location_link/module_access_store_name | 81 ++++++++++++ .../location_link/module_access_store_state | 79 ++++++++++++ .../definition/location_link/type_enum | 2 +- .../definition/location_link/type_record | 2 +- src/ls/definition.cr | 2 +- src/ls/definition/module_access.cr | 20 +++ src/ls/definition/type_id.cr | 14 ++ src/parsers/connect_variable.cr | 2 +- src/parsers/constant_access.cr | 4 +- src/parsers/constant_variable.cr | 24 ---- src/parsers/variable.cr | 8 +- 41 files changed, 2258 insertions(+), 34 deletions(-) create mode 100644 spec/language_server/definition/location/module_access_component_constant create mode 100644 spec/language_server/definition/location/module_access_component_function create mode 100644 spec/language_server/definition/location/module_access_component_gets create mode 100644 spec/language_server/definition/location/module_access_component_name create mode 100644 spec/language_server/definition/location/module_access_component_state create mode 100644 spec/language_server/definition/location/module_access_module_constant create mode 100644 spec/language_server/definition/location/module_access_module_function create mode 100644 spec/language_server/definition/location/module_access_module_multiple create mode 100644 spec/language_server/definition/location/module_access_module_name create mode 100644 spec/language_server/definition/location/module_access_module_name_shared create mode 100644 spec/language_server/definition/location/module_access_store_constant create mode 100644 spec/language_server/definition/location/module_access_store_function create mode 100644 spec/language_server/definition/location/module_access_store_gets create mode 100644 spec/language_server/definition/location/module_access_store_name create mode 100644 spec/language_server/definition/location/module_access_store_state create mode 100644 spec/language_server/definition/location_link/module_access_component_constant create mode 100644 spec/language_server/definition/location_link/module_access_component_function create mode 100644 spec/language_server/definition/location_link/module_access_component_gets create mode 100644 spec/language_server/definition/location_link/module_access_component_name create mode 100644 spec/language_server/definition/location_link/module_access_component_state create mode 100644 spec/language_server/definition/location_link/module_access_module_constant create mode 100644 spec/language_server/definition/location_link/module_access_module_function create mode 100644 spec/language_server/definition/location_link/module_access_module_multiple create mode 100644 spec/language_server/definition/location_link/module_access_module_name create mode 100644 spec/language_server/definition/location_link/module_access_module_name_shared create mode 100644 spec/language_server/definition/location_link/module_access_store_constant create mode 100644 spec/language_server/definition/location_link/module_access_store_function create mode 100644 spec/language_server/definition/location_link/module_access_store_gets create mode 100644 spec/language_server/definition/location_link/module_access_store_name create mode 100644 spec/language_server/definition/location_link/module_access_store_state create mode 100644 src/ls/definition/module_access.cr delete mode 100644 src/parsers/constant_variable.cr diff --git a/spec/language_server/definition/location/module_access_component_constant b/spec/language_server/definition/location/module_access_component_constant new file mode 100644 index 000000000..18b9c73a5 --- /dev/null +++ b/spec/language_server/definition/location/module_access_component_constant @@ -0,0 +1,63 @@ +global component Header { + const TITLE = "Mint" + + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header: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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + }, + "uri": "file://#{root_path}/header.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_component_function b/spec/language_server/definition/location/module_access_component_function new file mode 100644 index 000000000..5fad125e4 --- /dev/null +++ b/spec/language_server/definition/location/module_access_component_function @@ -0,0 +1,61 @@ +global component Header { + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.render() }> +
+ } +} +------------------------------------------------------------------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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 12 + } + }, + "uri": "file://#{root_path}/header.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_component_gets b/spec/language_server/definition/location/module_access_component_gets new file mode 100644 index 000000000..4f07c0d46 --- /dev/null +++ b/spec/language_server/definition/location/module_access_component_gets @@ -0,0 +1,65 @@ +global component Header { + get title : String { + "Mint" + } + + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + }, + "uri": "file://#{root_path}/header.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_component_name b/spec/language_server/definition/location/module_access_component_name new file mode 100644 index 000000000..36e989bc7 --- /dev/null +++ b/spec/language_server/definition/location/module_access_component_name @@ -0,0 +1,61 @@ +global component Header { + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.render() }> +
+ } +} +------------------------------------------------------------------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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 0, + "character": 17 + }, + "end": { + "line": 0, + "character": 23 + } + }, + "uri": "file://#{root_path}/header.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_component_state b/spec/language_server/definition/location/module_access_component_state new file mode 100644 index 000000000..5765cb23e --- /dev/null +++ b/spec/language_server/definition/location/module_access_component_state @@ -0,0 +1,63 @@ +global component Header { + state title = "Mint" + + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + }, + "uri": "file://#{root_path}/header.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_module_constant b/spec/language_server/definition/location/module_access_module_constant new file mode 100644 index 000000000..79925ada1 --- /dev/null +++ b/spec/language_server/definition/location/module_access_module_constant @@ -0,0 +1,59 @@ +module Header { + const TITLE = "Mint" +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { +
+ <{ Header: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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + }, + "uri": "file://#{root_path}/module.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_module_function b/spec/language_server/definition/location/module_access_module_function new file mode 100644 index 000000000..9fa9fdbab --- /dev/null +++ b/spec/language_server/definition/location/module_access_module_function @@ -0,0 +1,61 @@ +module Header { + fun title : String { + "Mint" + } +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + }, + "uri": "file://#{root_path}/module.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_module_multiple b/spec/language_server/definition/location/module_access_module_multiple new file mode 100644 index 000000000..bcae1a260 --- /dev/null +++ b/spec/language_server/definition/location/module_access_module_multiple @@ -0,0 +1,82 @@ +module Header { + fun title : String { + "Mint" + } +} +---------------------------------------------------------------file module1.mint +module Header { + fun description : String { + "Mint Lang" + } +} +---------------------------------------------------------------file module2.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": [ + { + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + }, + "uri": "file://#{root_path}/module1.mint" + }, + { + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + }, + "uri": "file://#{root_path}/module2.mint" + } + ], + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_module_name b/spec/language_server/definition/location/module_access_module_name new file mode 100644 index 000000000..5db5e6db5 --- /dev/null +++ b/spec/language_server/definition/location/module_access_module_name @@ -0,0 +1,61 @@ +module Header { + fun title : String { + "Mint" + } +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + }, + "uri": "file://#{root_path}/module.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_module_name_shared b/spec/language_server/definition/location/module_access_module_name_shared new file mode 100644 index 000000000..d7bece280 --- /dev/null +++ b/spec/language_server/definition/location/module_access_module_name_shared @@ -0,0 +1,68 @@ +record Header { + title : String +} +----------------------------------------------------------------file record.mint +module Header { + fun default : Header { + { title: "Mint" } + } +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { + let header = + Header.default() + +
+ <{ header.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": 3, + "character": 6 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + }, + "uri": "file://#{root_path}/module.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_store_constant b/spec/language_server/definition/location/module_access_store_constant new file mode 100644 index 000000000..a88e591dc --- /dev/null +++ b/spec/language_server/definition/location/module_access_store_constant @@ -0,0 +1,59 @@ +store Header { + const TITLE = "Mint" +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header: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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + }, + "uri": "file://#{root_path}/store.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_store_function b/spec/language_server/definition/location/module_access_store_function new file mode 100644 index 000000000..2158cd1f1 --- /dev/null +++ b/spec/language_server/definition/location/module_access_store_function @@ -0,0 +1,61 @@ +store Header { + fun title : String { + "Mint" + } +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + }, + "uri": "file://#{root_path}/store.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_store_gets b/spec/language_server/definition/location/module_access_store_gets new file mode 100644 index 000000000..15bc97f73 --- /dev/null +++ b/spec/language_server/definition/location/module_access_store_gets @@ -0,0 +1,61 @@ +store Header { + get title : String { + "Mint" + } +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + }, + "uri": "file://#{root_path}/store.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_store_name b/spec/language_server/definition/location/module_access_store_name new file mode 100644 index 000000000..56dd80611 --- /dev/null +++ b/spec/language_server/definition/location/module_access_store_name @@ -0,0 +1,61 @@ +store Header { + fun title : String { + "Mint" + } +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 0, + "character": 6 + }, + "end": { + "line": 0, + "character": 12 + } + }, + "uri": "file://#{root_path}/store.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/module_access_store_state b/spec/language_server/definition/location/module_access_store_state new file mode 100644 index 000000000..194af7ae2 --- /dev/null +++ b/spec/language_server/definition/location/module_access_store_state @@ -0,0 +1,59 @@ +store Header { + state title = "Mint" +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + }, + "uri": "file://#{root_path}/store.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/type_enum b/spec/language_server/definition/location/type_enum index 26f393d12..d397b8dde 100644 --- a/spec/language_server/definition/location/type_enum +++ b/spec/language_server/definition/location/type_enum @@ -3,7 +3,7 @@ enum Status { Ok } ----------------------------------------------------------------file status.mint -module Test { +module Status { fun success : Status { Status::Ok } diff --git a/spec/language_server/definition/location/type_record b/spec/language_server/definition/location/type_record index 8c6894980..308b6a810 100644 --- a/spec/language_server/definition/location/type_record +++ b/spec/language_server/definition/location/type_record @@ -4,7 +4,7 @@ record Article { title : String } ---------------------------------------------------------------file article.mint -module Test { +module Article { fun test : Article { { id: 1, diff --git a/spec/language_server/definition/location_link/module_access_component_constant b/spec/language_server/definition/location_link/module_access_component_constant new file mode 100644 index 000000000..01d5a2dda --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_component_constant @@ -0,0 +1,83 @@ +global component Header { + const TITLE = "Mint" + + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header: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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/header.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 22 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_component_function b/spec/language_server/definition/location_link/module_access_component_function new file mode 100644 index 000000000..0b029b2aa --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_component_function @@ -0,0 +1,81 @@ +global component Header { + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.render() }> +
+ } +} +------------------------------------------------------------------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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 22 + } + }, + "targetUri": "file://#{root_path}/header.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 12 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_component_gets b/spec/language_server/definition/location_link/module_access_component_gets new file mode 100644 index 000000000..2555b6ee1 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_component_gets @@ -0,0 +1,85 @@ +global component Header { + get title : String { + "Mint" + } + + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/header.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 5, + "character": 2 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_component_name b/spec/language_server/definition/location_link/module_access_component_name new file mode 100644 index 000000000..b669f0b49 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_component_name @@ -0,0 +1,81 @@ +global component Header { + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.render() }> +
+ } +} +------------------------------------------------------------------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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 9 + }, + "end": { + "line": 3, + "character": 15 + } + }, + "targetUri": "file://#{root_path}/header.mint", + "targetRange": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 1 + } + }, + "targetSelectionRange": { + "start": { + "line": 0, + "character": 17 + }, + "end": { + "line": 0, + "character": 23 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_component_state b/spec/language_server/definition/location_link/module_access_component_state new file mode 100644 index 000000000..1208ef692 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_component_state @@ -0,0 +1,83 @@ +global component Header { + state title = "Mint" + + fun render : Html { +
+ } +} +----------------------------------------------------------------file header.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/header.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 22 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_module_constant b/spec/language_server/definition/location_link/module_access_module_constant new file mode 100644 index 000000000..6896b0322 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_module_constant @@ -0,0 +1,79 @@ +module Header { + const TITLE = "Mint" +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { +
+ <{ Header: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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/module.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 22 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_module_function b/spec/language_server/definition/location_link/module_access_module_function new file mode 100644 index 000000000..5488f5465 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_module_function @@ -0,0 +1,81 @@ +module Header { + fun title : String { + "Mint" + } +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/module.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_module_multiple b/spec/language_server/definition/location_link/module_access_module_multiple new file mode 100644 index 000000000..eac409eee --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_module_multiple @@ -0,0 +1,122 @@ +module Header { + fun title : String { + "Mint" + } +} +---------------------------------------------------------------file module1.mint +module Header { + fun description : String { + "Mint Lang" + } +} +---------------------------------------------------------------file module2.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": [ + { + "originSelectionRange": { + "start": { + "line": 3, + "character": 9 + }, + "end": { + "line": 3, + "character": 15 + } + }, + "targetUri": "file://#{root_path}/module1.mint", + "targetRange": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 1 + } + }, + "targetSelectionRange": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + } + }, + { + "originSelectionRange": { + "start": { + "line": 3, + "character": 9 + }, + "end": { + "line": 3, + "character": 15 + } + }, + "targetUri": "file://#{root_path}/module2.mint", + "targetRange": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 1 + } + }, + "targetSelectionRange": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + } + } + ], + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_module_name b/spec/language_server/definition/location_link/module_access_module_name new file mode 100644 index 000000000..8b86b1571 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_module_name @@ -0,0 +1,81 @@ +module Header { + fun title : String { + "Mint" + } +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 9 + }, + "end": { + "line": 3, + "character": 15 + } + }, + "targetUri": "file://#{root_path}/module.mint", + "targetRange": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 1 + } + }, + "targetSelectionRange": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_module_name_shared b/spec/language_server/definition/location_link/module_access_module_name_shared new file mode 100644 index 000000000..4288b0f55 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_module_name_shared @@ -0,0 +1,88 @@ +record Header { + title : String +} +----------------------------------------------------------------file record.mint +module Header { + fun default : Header { + { title: "Mint" } + } +} +----------------------------------------------------------------file module.mint +component Test { + fun render : Html { + let header = + Header.default() + +
+ <{ header.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": 3, + "character": 6 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 6 + }, + "end": { + "line": 3, + "character": 12 + } + }, + "targetUri": "file://#{root_path}/module.mint", + "targetRange": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 1 + } + }, + "targetSelectionRange": { + "start": { + "line": 0, + "character": 7 + }, + "end": { + "line": 0, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_store_constant b/spec/language_server/definition/location_link/module_access_store_constant new file mode 100644 index 000000000..4fbb6fb7b --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_store_constant @@ -0,0 +1,79 @@ +store Header { + const TITLE = "Mint" +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header: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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/store.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 22 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_store_function b/spec/language_server/definition/location_link/module_access_store_function new file mode 100644 index 000000000..169011196 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_store_function @@ -0,0 +1,81 @@ +store Header { + fun title : String { + "Mint" + } +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/store.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_store_gets b/spec/language_server/definition/location_link/module_access_store_gets new file mode 100644 index 000000000..15b5e99be --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_store_gets @@ -0,0 +1,81 @@ +store Header { + get title : String { + "Mint" + } +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/store.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 4, + "character": 0 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 11 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_store_name b/spec/language_server/definition/location_link/module_access_store_name new file mode 100644 index 000000000..96c9eb66e --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_store_name @@ -0,0 +1,81 @@ +store Header { + fun title : String { + "Mint" + } +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 9 + }, + "end": { + "line": 3, + "character": 15 + } + }, + "targetUri": "file://#{root_path}/store.mint", + "targetRange": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 4, + "character": 1 + } + }, + "targetSelectionRange": { + "start": { + "line": 0, + "character": 6 + }, + "end": { + "line": 0, + "character": 12 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/module_access_store_state b/spec/language_server/definition/location_link/module_access_store_state new file mode 100644 index 000000000..b473d6795 --- /dev/null +++ b/spec/language_server/definition/location_link/module_access_store_state @@ -0,0 +1,79 @@ +store Header { + state title = "Mint" +} +-----------------------------------------------------------------file store.mint +component Test { + fun render : Html { +
+ <{ Header.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": 3, + "character": 16 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 16 + }, + "end": { + "line": 3, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/store.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 22 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/type_enum b/spec/language_server/definition/location_link/type_enum index 632b406f2..2557b4ec8 100644 --- a/spec/language_server/definition/location_link/type_enum +++ b/spec/language_server/definition/location_link/type_enum @@ -3,7 +3,7 @@ enum Status { Ok } ----------------------------------------------------------------file status.mint -module Test { +module Status { fun success : Status { Status::Ok } diff --git a/spec/language_server/definition/location_link/type_record b/spec/language_server/definition/location_link/type_record index 3d9497623..7f5540979 100644 --- a/spec/language_server/definition/location_link/type_record +++ b/spec/language_server/definition/location_link/type_record @@ -4,7 +4,7 @@ record Article { title : String } ---------------------------------------------------------------file article.mint -module Test { +module Article { fun test : Article { { id: 1, diff --git a/src/ls/definition.cr b/src/ls/definition.cr index 585a5027d..62422806a 100644 --- a/src/ls/definition.cr +++ b/src/ls/definition.cr @@ -4,7 +4,7 @@ module Mint class Definition < LSP::RequestMessage property params : LSP::TextDocumentPositionParams - def execute(server) : LSP::LocationLink | LSP::Location? + def execute(server) : Array(LSP::LocationLink | LSP::Location) | LSP::LocationLink | LSP::Location | Nil uri = URI.parse(params.text_document.uri) diff --git a/src/ls/definition/module_access.cr b/src/ls/definition/module_access.cr new file mode 100644 index 000000000..6a67c510d --- /dev/null +++ b/src/ls/definition/module_access.cr @@ -0,0 +1,20 @@ +module Mint + module LS + class Definition < LSP::RequestMessage + def definition(node : Ast::ModuleAccess, server : Server, workspace : Workspace, stack : Array(Ast::Node)) + lookup = workspace.type_checker.lookups[node.variable]? + + if lookup + case lookup + when Ast::Property, + Ast::Constant, + Ast::Function, + Ast::State, + Ast::Get + location_link server, node.variable, lookup.name, lookup + end + end + end + end + end +end diff --git a/src/ls/definition/type_id.cr b/src/ls/definition/type_id.cr index eed5a2a24..ad74293d1 100644 --- a/src/ls/definition/type_id.cr +++ b/src/ls/definition/type_id.cr @@ -2,6 +2,20 @@ module Mint module LS class Definition < LSP::RequestMessage def definition(node : Ast::TypeId, server : Server, workspace : Workspace, stack : Array(Ast::Node)) + case stack[1]? + when Ast::ModuleAccess + links = workspace.ast.modules + .select(&.name.value.==(node.value)) + .reject(&.in?(Core.ast.nodes)) + .sort_by!(&.input.file) + .map do |mod| + location_link server, node, mod.name, mod + end + + return links.first if links.size == 1 + return links unless links.empty? + end + found = workspace.ast.enums.find(&.name.value.==(node.value)) || workspace.ast.records.find(&.name.value.==(node.value)) || diff --git a/src/parsers/connect_variable.cr b/src/parsers/connect_variable.cr index 62f195174..d1ab6cc7f 100644 --- a/src/parsers/connect_variable.cr +++ b/src/parsers/connect_variable.cr @@ -4,7 +4,7 @@ module Mint def connect_variable start do |start_position| - value = variable(track: false) || constant_variable + value = variable(track: false) || variable_constant next unless value diff --git a/src/parsers/constant_access.cr b/src/parsers/constant_access.cr index d981a66fe..06df8587b 100644 --- a/src/parsers/constant_access.cr +++ b/src/parsers/constant_access.cr @@ -11,11 +11,11 @@ module Mint next unless name variable = - constant_variable + variable_constant next unless variable - Ast::ModuleAccess.new( + self << Ast::ModuleAccess.new( from: start_position, variable: variable, constant: true, diff --git a/src/parsers/constant_variable.cr b/src/parsers/constant_variable.cr deleted file mode 100644 index 24fde43d6..000000000 --- a/src/parsers/constant_variable.cr +++ /dev/null @@ -1,24 +0,0 @@ -module Mint - class Parser - def constant_variable : Ast::Variable? - start do |start_position| - head = - gather { chars &.ascii_uppercase? } - - tail = - gather { chars { |char| char.ascii_uppercase? || char.ascii_number? || char == '_' } } - - next unless head || tail - - name = - "#{head}#{tail}" - - Ast::Variable.new( - from: start_position, - to: position, - input: data, - value: name) - end - end - end -end diff --git a/src/parsers/variable.cr b/src/parsers/variable.cr index 21ba86fcf..7042da0c1 100644 --- a/src/parsers/variable.cr +++ b/src/parsers/variable.cr @@ -43,7 +43,7 @@ module Mint end end - def variable_constant! : Ast::Variable + def variable_constant : Ast::Variable? start do |start_position| head = gather { chars &.ascii_uppercase? } @@ -51,7 +51,7 @@ module Mint tail = gather { chars { |char| char.ascii_uppercase? || char.ascii_number? || char == '_' } } - raise ConstantExpectedName unless head + next unless head value = "#{head}#{tail}" @@ -63,6 +63,10 @@ module Mint end end + def variable_constant! : Ast::Variable + variable_constant || raise ConstantExpectedName + end + def variable!(error : SyntaxError.class, track = true) : Ast::Variable variable(track) || raise error end