diff --git a/Dockerfile b/Dockerfile index f98b59612..c12a06a05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # We are using crystal as image we are building the binary on -FROM crystallang/crystal:1.8.2-alpine AS build +FROM crystallang/crystal:1.9.1-alpine AS build # Create a build directory and set it as default RUN mkdir -p /opt/mint diff --git a/shard.lock b/shard.lock index 7e0566914..b66752cf1 100644 --- a/shard.lock +++ b/shard.lock @@ -6,7 +6,7 @@ shards: ameba: git: https://github.com/crystal-ameba/ameba.git - version: 1.4.3+git.commit.8c9d234d0b06d945d0cf841dfa0596734acc715c + version: 1.5.0 backtracer: git: https://github.com/sija/backtracer.cr.git diff --git a/shard.yml b/shard.yml index 85f60db55..749f2eeaa 100644 --- a/shard.yml +++ b/shard.yml @@ -24,7 +24,7 @@ dependencies: development_dependencies: ameba: github: crystal-ameba/ameba - branch: master + version: ~> 1.5.0 targets: mint: diff --git a/spec/compilers/provider_with_items b/spec/compilers/provider_with_items new file mode 100644 index 000000000..e1cfe9c0e --- /dev/null +++ b/spec/compilers/provider_with_items @@ -0,0 +1,102 @@ +record Subscription { + a : Bool, + b : Bool +} + +provider Provider : Subscription { + const NAME = "hello" + + state a : String = "" + + get b : String { + a + } + + fun name : String { + NAME + } +} + +component Main { + use Provider { + a: true, + b: false + } + + fun render { +
+ } +} +-------------------------------------------------------------------------------- +const A = _R({ + a: [ + "a", + Decoder.boolean + ], + b: [ + "b", + Decoder.boolean + ] +}); + +const B = new(class extends _P { + constructor() { + super(); + + this.state = { + c: `` + }; + + this._d({ + b: () => { + return `hello` + } + }); + } + + get c() { + return this.state.c; + } + + get d() { + return this.c + } + + a() { + return this.b; + } +}); + +class C extends _C { + componentWillUnmount() { + B._unsubscribe(this); + } + + componentDidUpdate() { + if (true) { + B._subscribe(this, new A({ + a: true, + b: false + })) + } else { + B._unsubscribe(this) + }; + } + + componentDidMount() { + if (true) { + B._subscribe(this, new A({ + a: true, + b: false + })) + } else { + B._unsubscribe(this) + }; + } + + render() { + return _h("div", {}); + } +}; + +C.displayName = "Main"; diff --git a/spec/formatters/constant_provider b/spec/formatters/constant_provider new file mode 100644 index 000000000..4e2eb6646 --- /dev/null +++ b/spec/formatters/constant_provider @@ -0,0 +1,24 @@ +record Subscription { + a : Bool +} + +provider Provider:Subscription { + /* Comment */constNAME="hello" + + fun name:String { + NAME + } +} +-------------------------------------------------------------------------------- +record Subscription { + a : Bool +} + +provider Provider : Subscription { + /* Comment */ + const NAME = "hello" + + fun name : String { + NAME + } +} diff --git a/spec/formatters/provider_with_items b/spec/formatters/provider_with_items new file mode 100644 index 000000000..4efc415f6 --- /dev/null +++ b/spec/formatters/provider_with_items @@ -0,0 +1,34 @@ +record Subscription { + a : Bool +} + +provider Provider:Subscription { +/* Comment */constNAME="hello" + + state a :String = "" + getb:String { + a + } + fun name:String { + NAME + } +} +-------------------------------------------------------------------------------- +record Subscription { + a : Bool +} + +provider Provider : Subscription { + /* Comment */ + const NAME = "hello" + + state a : String = "" + + get b : String { + a + } + + fun name : String { + NAME + } +} 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/variable_block_statement_target b/spec/language_server/definition/location/variable_block_statement_target new file mode 100644 index 000000000..d75cc726f --- /dev/null +++ b/spec/language_server/definition/location/variable_block_statement_target @@ -0,0 +1,55 @@ +module Test { + fun upperCaseMint : String { + let test = + "Mint" + + String.toUpperCase(test) + } +} +------------------------------------------------------------------file test.mint +{ + "id": 0, + "method": "initialize", + "params": { + "capabilities": { + "textDocument": { + "definition": { + "linkSupport": false + } + } + } + } +} +-------------------------------------------------------------------------request +{ + "id": 1, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 5, + "character": 23 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 2, + "character": 8 + }, + "end": { + "line": 2, + "character": 12 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_casebranch_enumdestructuring b/spec/language_server/definition/location/variable_casebranch_enumdestructuring new file mode 100644 index 000000000..e359f6743 --- /dev/null +++ b/spec/language_server/definition/location/variable_casebranch_enumdestructuring @@ -0,0 +1,61 @@ +enum Status { + Error + Ok(text : String) +} + +module Test { + fun toString (status : Status) : String { + case status { + Status::Ok(text) => text + Status::Error => "error" + } + } +} +------------------------------------------------------------------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": 8, + "character": 26 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 8, + "character": 17 + }, + "end": { + "line": 8, + "character": 21 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_component_connect b/spec/language_server/definition/location/variable_component_connect new file mode 100644 index 000000000..7d687e9ec --- /dev/null +++ b/spec/language_server/definition/location/variable_component_connect @@ -0,0 +1,60 @@ +component Test { + connect Theme exposing { primary } + + fun render : Html { +
+ <{ primary }> +
+ } +} +------------------------------------------------------------------file test.mint +store Theme { + state primary : String = "#00a0e8" +} +-----------------------------------------------------------------file store.mint +{ + "id": 0, + "method": "initialize", + "params": { + "capabilities": { + "textDocument": { + "definition": { + "linkSupport": false + } + } + } + } +} +-------------------------------------------------------------------------request +{ + "id": 1, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 27 + }, + "end": { + "line": 1, + "character": 34 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_component_connect_as b/spec/language_server/definition/location/variable_component_connect_as new file mode 100644 index 000000000..fcbfd2e46 --- /dev/null +++ b/spec/language_server/definition/location/variable_component_connect_as @@ -0,0 +1,60 @@ +component Test { + connect Theme exposing { primary as primaryColor } + + fun render : Html { +
+ <{ primaryColor }> +
+ } +} +------------------------------------------------------------------file test.mint +store Theme { + state primary : String = "#00a0e8" +} +-----------------------------------------------------------------file store.mint +{ + "id": 0, + "method": "initialize", + "params": { + "capabilities": { + "textDocument": { + "definition": { + "linkSupport": false + } + } + } + } +} +-------------------------------------------------------------------------request +{ + "id": 1, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 38 + }, + "end": { + "line": 1, + "character": 50 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_component_constant b/spec/language_server/definition/location/variable_component_constant new file mode 100644 index 000000000..60cb16028 --- /dev/null +++ b/spec/language_server/definition/location/variable_component_constant @@ -0,0 +1,57 @@ +component Test { + const TEXT = "Mint" + + fun render : Html { +
+ <{ TEXT }> +
+ } +} +------------------------------------------------------------------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": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_component_function b/spec/language_server/definition/location/variable_component_function new file mode 100644 index 000000000..5e2911d5d --- /dev/null +++ b/spec/language_server/definition/location/variable_component_function @@ -0,0 +1,59 @@ +component Test { + fun text : String { + "Mint" + } + + fun render : Html { +
+ <{ text() }> +
+ } +} +------------------------------------------------------------------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": 7, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 10 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_component_get b/spec/language_server/definition/location/variable_component_get new file mode 100644 index 000000000..f0b6cec56 --- /dev/null +++ b/spec/language_server/definition/location/variable_component_get @@ -0,0 +1,59 @@ +component Test { + get text : String { + "Mint" + } + + fun render : Html { +
+ <{ text }> +
+ } +} +------------------------------------------------------------------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": 7, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 10 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_component_property b/spec/language_server/definition/location/variable_component_property new file mode 100644 index 000000000..6be5ab434 --- /dev/null +++ b/spec/language_server/definition/location/variable_component_property @@ -0,0 +1,57 @@ +component Test { + property text : String = "Mint" + + fun render : Html { +
+ <{ text }> +
+ } +} +------------------------------------------------------------------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": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 11 + }, + "end": { + "line": 1, + "character": 15 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_component_state b/spec/language_server/definition/location/variable_component_state new file mode 100644 index 000000000..afce458b6 --- /dev/null +++ b/spec/language_server/definition/location/variable_component_state @@ -0,0 +1,57 @@ +component Test { + state text : String = "Mint" + + fun render : Html { +
+ <{ text }> +
+ } +} +------------------------------------------------------------------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": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_for b/spec/language_server/definition/location/variable_for new file mode 100644 index 000000000..7effba3f8 --- /dev/null +++ b/spec/language_server/definition/location/variable_for @@ -0,0 +1,55 @@ +module Test { + fun uppercase (values : Array(String)) : Array(String) { + for value of values { + String.toUpperCase(value) + } + } +} +------------------------------------------------------------------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": 25 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 2, + "character": 8 + }, + "end": { + "line": 2, + "character": 13 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_for_argument_stop b/spec/language_server/definition/location/variable_for_argument_stop new file mode 100644 index 000000000..359d8768a --- /dev/null +++ b/spec/language_server/definition/location/variable_for_argument_stop @@ -0,0 +1,43 @@ +module Test { + fun uppercase (value : String) : Array(String) { + for value of String.split(value, ",") { + String.toUpperCase(value) + } + } +} +------------------------------------------------------------------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": 2, + "character": 8 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": null, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_for_subject b/spec/language_server/definition/location/variable_for_subject new file mode 100644 index 000000000..003e00b12 --- /dev/null +++ b/spec/language_server/definition/location/variable_for_subject @@ -0,0 +1,55 @@ +module Test { + fun uppercase (value : String) : Array(String) { + for value of String.split(value, ",") { + String.toUpperCase(value) + } + } +} +------------------------------------------------------------------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": 2, + "character": 30 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 17 + }, + "end": { + "line": 1, + "character": 22 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_function_argument b/spec/language_server/definition/location/variable_function_argument new file mode 100644 index 000000000..aa54676df --- /dev/null +++ b/spec/language_server/definition/location/variable_function_argument @@ -0,0 +1,53 @@ +module Test { + fun toString (status : String) : String { + status + } +} +------------------------------------------------------------------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": 2, + "character": 4 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 16 + }, + "end": { + "line": 1, + "character": 22 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_function_argument_stop b/spec/language_server/definition/location/variable_function_argument_stop new file mode 100644 index 000000000..58f659bae --- /dev/null +++ b/spec/language_server/definition/location/variable_function_argument_stop @@ -0,0 +1,29 @@ +store Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + next { text: text } + } +} +------------------------------------------------------------------file test.mint +{ + "jsonrpc": "2.0", + "id": 0, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 3, + "character": 12 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": null, + "id": 0 +} +------------------------------------------------------------------------response 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_nextcall_component b/spec/language_server/definition/location/variable_nextcall_component new file mode 100644 index 000000000..0f8c2f191 --- /dev/null +++ b/spec/language_server/definition/location/variable_nextcall_component @@ -0,0 +1,59 @@ +component Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + next { text: text } + } + + fun 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": 4, + "character": 11 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_nextcall_record b/spec/language_server/definition/location/variable_nextcall_record new file mode 100644 index 000000000..c03cad4ba --- /dev/null +++ b/spec/language_server/definition/location/variable_nextcall_record @@ -0,0 +1,74 @@ +record Article { + id : Number, + description : String, + title : String +} + +store Test { + state article : Article = + { + id: 1, + description: "Mint Lang", + title: "Mint" + } + + fun load : Promise(Void) { + next + { + article: + { + id: 1, + description: "Mint Lang", + title: "Mint" + } + } + } +} +------------------------------------------------------------------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": 20, + "character": 12 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 2, + "character": 2 + }, + "end": { + "line": 2, + "character": 13 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_nextcall_store b/spec/language_server/definition/location/variable_nextcall_store new file mode 100644 index 000000000..bb9adba8e --- /dev/null +++ b/spec/language_server/definition/location/variable_nextcall_store @@ -0,0 +1,55 @@ +store Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + next { text: text } + } +} +------------------------------------------------------------------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": 11 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_nextcall_value b/spec/language_server/definition/location/variable_nextcall_value new file mode 100644 index 000000000..e6621c346 --- /dev/null +++ b/spec/language_server/definition/location/variable_nextcall_value @@ -0,0 +1,58 @@ +store Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + let newText = + "Mint" + + next { text: newText } + } +} +------------------------------------------------------------------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": 7, + "character": 17 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 4, + "character": 8 + }, + "end": { + "line": 4, + "character": 15 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_provider_constant b/spec/language_server/definition/location/variable_provider_constant new file mode 100644 index 000000000..8e3ff65e5 --- /dev/null +++ b/spec/language_server/definition/location/variable_provider_constant @@ -0,0 +1,59 @@ +record Subscription { + a : Bool +} + +provider Provider : Subscription { + 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": 8, + "character": 4 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 5, + "character": 8 + }, + "end": { + "line": 5, + "character": 13 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_recordfield_key b/spec/language_server/definition/location/variable_recordfield_key new file mode 100644 index 000000000..6bbf9f18d --- /dev/null +++ b/spec/language_server/definition/location/variable_recordfield_key @@ -0,0 +1,63 @@ +record Article { + id : Number, + description : String, + title : String +} + +module Test { + fun makeArticle (title : String) : Article { + { + id: 1, + description: "Mint Lang", + 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": 9, + "character": 6 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 4 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_recordfield_value b/spec/language_server/definition/location/variable_recordfield_value new file mode 100644 index 000000000..374e8cb6d --- /dev/null +++ b/spec/language_server/definition/location/variable_recordfield_value @@ -0,0 +1,63 @@ +record Article { + id : Number, + description : String, + title : String +} +---------------------------------------------------------------file article.mint +module Test { + fun makeArticle (title : String) : Article { + { + id: 1, + description: "Mint Lang", + 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": 5, + "character": 13 + } + }, + "method": "textDocument/definition" +} +------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 19 + }, + "end": { + "line": 1, + "character": 24 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_store_constant b/spec/language_server/definition/location/variable_store_constant new file mode 100644 index 000000000..afcf3dd85 --- /dev/null +++ b/spec/language_server/definition/location/variable_store_constant @@ -0,0 +1,55 @@ +store Test { + const TITLE = "title" + + fun getTitle : 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_store_function b/spec/language_server/definition/location/variable_store_function new file mode 100644 index 000000000..8f27064df --- /dev/null +++ b/spec/language_server/definition/location/variable_store_function @@ -0,0 +1,57 @@ +store Test { + fun load (text : String) : Promise(Void) { + Promise.never() + } + + fun dashboard : Promise(Void) { + await load("Mint") + } +} +------------------------------------------------------------------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": 6, + "character": 10 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 10 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_store_get b/spec/language_server/definition/location/variable_store_get new file mode 100644 index 000000000..ff9211007 --- /dev/null +++ b/spec/language_server/definition/location/variable_store_get @@ -0,0 +1,61 @@ +store Test { + get description : String { + "description" + } + + fun load (text : String) : Promise(Void) { + Promise.never() + } + + fun dashboard : Promise(Void) { + await load(description) + } +} +------------------------------------------------------------------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": 10, + "character": 15 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "range": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 17 + } + }, + "uri": "file://#{root_path}/test.mint" + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location/variable_store_state b/spec/language_server/definition/location/variable_store_state new file mode 100644 index 000000000..a70091112 --- /dev/null +++ b/spec/language_server/definition/location/variable_store_state @@ -0,0 +1,59 @@ +store Test { + state title : String = "title" + + fun load (text : String) : Promise(Void) { + Promise.never() + } + + fun dashboard : Promise(Void) { + await load(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": 8, + "character": 15 + } + }, + "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/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/spec/language_server/definition/location_link/variable_block_statement_target b/spec/language_server/definition/location_link/variable_block_statement_target new file mode 100644 index 000000000..07e7d96b5 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_block_statement_target @@ -0,0 +1,75 @@ +module Test { + fun upperCaseMint : String { + let test = + "Mint" + + String.toUpperCase(test) + } +} +------------------------------------------------------------------file test.mint +{ + "id": 0, + "method": "initialize", + "params": { + "capabilities": { + "textDocument": { + "definition": { + "linkSupport": true + } + } + } + } +} +-------------------------------------------------------------------------request +{ + "id": 1, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 5, + "character": 23 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 5, + "character": 23 + }, + "end": { + "line": 5, + "character": 27 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 3, + "character": 12 + } + }, + "targetSelectionRange": { + "start": { + "line": 2, + "character": 8 + }, + "end": { + "line": 2, + "character": 12 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_casebranch_enumdestructuring b/spec/language_server/definition/location_link/variable_casebranch_enumdestructuring new file mode 100644 index 000000000..4eba5aceb --- /dev/null +++ b/spec/language_server/definition/location_link/variable_casebranch_enumdestructuring @@ -0,0 +1,81 @@ +enum Status { + Error + Ok(text : String) +} + +module Test { + fun toString (status : Status) : String { + case status { + Status::Ok(text) => text + Status::Error => "error" + } + } +} +------------------------------------------------------------------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": 8, + "character": 26 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 8, + "character": 26 + }, + "end": { + "line": 8, + "character": 30 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 8, + "character": 6 + }, + "end": { + "line": 8, + "character": 22 + } + }, + "targetSelectionRange": { + "start": { + "line": 8, + "character": 17 + }, + "end": { + "line": 8, + "character": 21 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_component_connect b/spec/language_server/definition/location_link/variable_component_connect new file mode 100644 index 000000000..1b2cef32f --- /dev/null +++ b/spec/language_server/definition/location_link/variable_component_connect @@ -0,0 +1,80 @@ +component Test { + connect Theme exposing { primary } + + fun render : Html { +
+ <{ primary }> +
+ } +} +------------------------------------------------------------------file test.mint +store Theme { + state primary : String = "#00a0e8" +} +-----------------------------------------------------------------file store.mint +{ + "id": 0, + "method": "initialize", + "params": { + "capabilities": { + "textDocument": { + "definition": { + "linkSupport": true + } + } + } + } +} +-------------------------------------------------------------------------request +{ + "id": 1, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 5, + "character": 9 + }, + "end": { + "line": 5, + "character": 16 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 36 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 27 + }, + "end": { + "line": 1, + "character": 34 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_component_connect_as b/spec/language_server/definition/location_link/variable_component_connect_as new file mode 100644 index 000000000..6effa0999 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_component_connect_as @@ -0,0 +1,80 @@ +component Test { + connect Theme exposing { primary as primaryColor } + + fun render : Html { +
+ <{ primaryColor }> +
+ } +} +------------------------------------------------------------------file test.mint +store Theme { + state primary : String = "#00a0e8" +} +-----------------------------------------------------------------file store.mint +{ + "id": 0, + "method": "initialize", + "params": { + "capabilities": { + "textDocument": { + "definition": { + "linkSupport": true + } + } + } + } +} +-------------------------------------------------------------------------request +{ + "id": 1, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 5, + "character": 9 + }, + "end": { + "line": 5, + "character": 21 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 52 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 38 + }, + "end": { + "line": 1, + "character": 50 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_component_constant b/spec/language_server/definition/location_link/variable_component_constant new file mode 100644 index 000000000..03022a727 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_component_constant @@ -0,0 +1,77 @@ +component Test { + const TEXT = "Mint" + + fun render : Html { +
+ <{ TEXT }> +
+ } +} +------------------------------------------------------------------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": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 5, + "character": 9 + }, + "end": { + "line": 5, + "character": 13 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 21 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_component_function b/spec/language_server/definition/location_link/variable_component_function new file mode 100644 index 000000000..00126bf09 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_component_function @@ -0,0 +1,79 @@ +component Test { + fun text : String { + "Mint" + } + + fun render : Html { +
+ <{ text() }> +
+ } +} +------------------------------------------------------------------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": 7, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 7, + "character": 9 + }, + "end": { + "line": 7, + "character": 13 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 10 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_component_get b/spec/language_server/definition/location_link/variable_component_get new file mode 100644 index 000000000..1d5fcd4ca --- /dev/null +++ b/spec/language_server/definition/location_link/variable_component_get @@ -0,0 +1,79 @@ +component Test { + get text : String { + "Mint" + } + + fun render : Html { +
+ <{ text }> +
+ } +} +------------------------------------------------------------------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": 7, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 7, + "character": 9 + }, + "end": { + "line": 7, + "character": 13 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 5, + "character": 2 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 10 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_component_property b/spec/language_server/definition/location_link/variable_component_property new file mode 100644 index 000000000..ce61b0357 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_component_property @@ -0,0 +1,77 @@ +component Test { + property text : String = "Mint" + + fun render : Html { +
+ <{ text }> +
+ } +} +------------------------------------------------------------------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": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 5, + "character": 9 + }, + "end": { + "line": 5, + "character": 13 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 33 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 11 + }, + "end": { + "line": 1, + "character": 15 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_component_state b/spec/language_server/definition/location_link/variable_component_state new file mode 100644 index 000000000..e8705f482 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_component_state @@ -0,0 +1,77 @@ +component Test { + state text : String = "Mint" + + fun render : Html { +
+ <{ text }> +
+ } +} +------------------------------------------------------------------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": 5, + "character": 9 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 5, + "character": 9 + }, + "end": { + "line": 5, + "character": 13 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 30 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_for b/spec/language_server/definition/location_link/variable_for new file mode 100644 index 000000000..abd703d41 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_for @@ -0,0 +1,75 @@ +module Test { + fun uppercase (values : Array(String)) : Array(String) { + for value of values { + String.toUpperCase(value) + } + } +} +------------------------------------------------------------------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": 25 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 3, + "character": 25 + }, + "end": { + "line": 3, + "character": 30 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 5, + "character": 2 + } + }, + "targetSelectionRange": { + "start": { + "line": 2, + "character": 8 + }, + "end": { + "line": 2, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_for_argument_stop b/spec/language_server/definition/location_link/variable_for_argument_stop new file mode 100644 index 000000000..951f304ff --- /dev/null +++ b/spec/language_server/definition/location_link/variable_for_argument_stop @@ -0,0 +1,43 @@ +module Test { + fun uppercase (value : String) : Array(String) { + for value of String.split(value, ",") { + String.toUpperCase(value) + } + } +} +------------------------------------------------------------------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": 2, + "character": 8 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": null, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_for_subject b/spec/language_server/definition/location_link/variable_for_subject new file mode 100644 index 000000000..3c41c018e --- /dev/null +++ b/spec/language_server/definition/location_link/variable_for_subject @@ -0,0 +1,75 @@ +module Test { + fun uppercase (value : String) : Array(String) { + for value of String.split(value, ",") { + String.toUpperCase(value) + } + } +} +------------------------------------------------------------------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": 2, + "character": 30 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 2, + "character": 30 + }, + "end": { + "line": 2, + "character": 35 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 17 + }, + "end": { + "line": 1, + "character": 31 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 17 + }, + "end": { + "line": 1, + "character": 22 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_function_argument b/spec/language_server/definition/location_link/variable_function_argument new file mode 100644 index 000000000..78b9f72a3 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_function_argument @@ -0,0 +1,73 @@ +module Test { + fun toString (status : String) : String { + status + } +} +------------------------------------------------------------------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": 2, + "character": 4 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 2, + "character": 4 + }, + "end": { + "line": 2, + "character": 10 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 16 + }, + "end": { + "line": 1, + "character": 31 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 16 + }, + "end": { + "line": 1, + "character": 22 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_function_argument_stop b/spec/language_server/definition/location_link/variable_function_argument_stop new file mode 100644 index 000000000..58f659bae --- /dev/null +++ b/spec/language_server/definition/location_link/variable_function_argument_stop @@ -0,0 +1,29 @@ +store Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + next { text: text } + } +} +------------------------------------------------------------------file test.mint +{ + "jsonrpc": "2.0", + "id": 0, + "params": { + "textDocument": { + "uri": "file://#{root_path}/test.mint" + }, + "position": { + "line": 3, + "character": 12 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": null, + "id": 0 +} +------------------------------------------------------------------------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_nextcall_component b/spec/language_server/definition/location_link/variable_nextcall_component new file mode 100644 index 000000000..65bb1e6ff --- /dev/null +++ b/spec/language_server/definition/location_link/variable_nextcall_component @@ -0,0 +1,79 @@ +component Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + next { text: text } + } + + fun 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": 4, + "character": 11 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 4, + "character": 11 + }, + "end": { + "line": 4, + "character": 15 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 26 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_nextcall_record b/spec/language_server/definition/location_link/variable_nextcall_record new file mode 100644 index 000000000..b8a376929 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_nextcall_record @@ -0,0 +1,94 @@ +record Article { + id : Number, + description : String, + title : String +} + +store Test { + state article : Article = + { + id: 1, + description: "Mint Lang", + title: "Mint" + } + + fun load : Promise(Void) { + next + { + article: + { + id: 1, + description: "Mint Lang", + title: "Mint" + } + } + } +} +------------------------------------------------------------------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": 20, + "character": 12 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 20, + "character": 12 + }, + "end": { + "line": 20, + "character": 23 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 2, + "character": 2 + }, + "end": { + "line": 2, + "character": 22 + } + }, + "targetSelectionRange": { + "start": { + "line": 2, + "character": 2 + }, + "end": { + "line": 2, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_nextcall_store b/spec/language_server/definition/location_link/variable_nextcall_store new file mode 100644 index 000000000..61de09f1c --- /dev/null +++ b/spec/language_server/definition/location_link/variable_nextcall_store @@ -0,0 +1,75 @@ +store Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + next { text: text } + } +} +------------------------------------------------------------------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": 11 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 4, + "character": 11 + }, + "end": { + "line": 4, + "character": 15 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 26 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 8 + }, + "end": { + "line": 1, + "character": 12 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_nextcall_value b/spec/language_server/definition/location_link/variable_nextcall_value new file mode 100644 index 000000000..bd00bd2e9 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_nextcall_value @@ -0,0 +1,78 @@ +store Test { + state text : String = "" + + fun load (text : String) : Promise(Void) { + let newText = + "Mint" + + next { text: newText } + } +} +------------------------------------------------------------------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": 7, + "character": 17 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 7, + "character": 17 + }, + "end": { + "line": 7, + "character": 24 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 4, + "character": 4 + }, + "end": { + "line": 5, + "character": 12 + } + }, + "targetSelectionRange": { + "start": { + "line": 4, + "character": 8 + }, + "end": { + "line": 4, + "character": 15 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_provider_constant b/spec/language_server/definition/location_link/variable_provider_constant new file mode 100644 index 000000000..4f18c8a0a --- /dev/null +++ b/spec/language_server/definition/location_link/variable_provider_constant @@ -0,0 +1,79 @@ +record Subscription { + a : Bool +} + +provider Provider : Subscription { + 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": 8, + "character": 4 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 8, + "character": 4 + }, + "end": { + "line": 8, + "character": 9 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 5, + "character": 2 + }, + "end": { + "line": 5, + "character": 23 + } + }, + "targetSelectionRange": { + "start": { + "line": 5, + "character": 8 + }, + "end": { + "line": 5, + "character": 13 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_recordfield_key b/spec/language_server/definition/location_link/variable_recordfield_key new file mode 100644 index 000000000..5846bfacb --- /dev/null +++ b/spec/language_server/definition/location_link/variable_recordfield_key @@ -0,0 +1,83 @@ +record Article { + id : Number, + description : String, + title : String +} + +module Test { + fun makeArticle (title : String) : Article { + { + id: 1, + description: "Mint Lang", + 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": 9, + "character": 6 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 9, + "character": 6 + }, + "end": { + "line": 9, + "character": 8 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 13 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 4 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_recordfield_value b/spec/language_server/definition/location_link/variable_recordfield_value new file mode 100644 index 000000000..c80653428 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_recordfield_value @@ -0,0 +1,83 @@ +record Article { + id : Number, + description : String, + title : String +} +---------------------------------------------------------------file article.mint +module Test { + fun makeArticle (title : String) : Article { + { + id: 1, + description: "Mint Lang", + 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": 5, + "character": 13 + } + }, + "method": "textDocument/definition" +} +------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 5, + "character": 13 + }, + "end": { + "line": 5, + "character": 18 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 19 + }, + "end": { + "line": 1, + "character": 33 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 19 + }, + "end": { + "line": 1, + "character": 24 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_store_constant b/spec/language_server/definition/location_link/variable_store_constant new file mode 100644 index 000000000..30d3dd4f7 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_store_constant @@ -0,0 +1,75 @@ +store Test { + const TITLE = "title" + + fun getTitle : 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_store_function b/spec/language_server/definition/location_link/variable_store_function new file mode 100644 index 000000000..fa4c95c04 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_store_function @@ -0,0 +1,77 @@ +store Test { + fun load (text : String) : Promise(Void) { + Promise.never() + } + + fun dashboard : Promise(Void) { + await load("Mint") + } +} +------------------------------------------------------------------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": 6, + "character": 10 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 6, + "character": 10 + }, + "end": { + "line": 6, + "character": 14 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 3, + "character": 3 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 10 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_store_get b/spec/language_server/definition/location_link/variable_store_get new file mode 100644 index 000000000..853222a93 --- /dev/null +++ b/spec/language_server/definition/location_link/variable_store_get @@ -0,0 +1,81 @@ +store Test { + get description : String { + "description" + } + + fun load (text : String) : Promise(Void) { + Promise.never() + } + + fun dashboard : Promise(Void) { + await load(description) + } +} +------------------------------------------------------------------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": 10, + "character": 15 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 10, + "character": 15 + }, + "end": { + "line": 10, + "character": 26 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 5, + "character": 2 + } + }, + "targetSelectionRange": { + "start": { + "line": 1, + "character": 6 + }, + "end": { + "line": 1, + "character": 17 + } + } + }, + "id": 1 +} +------------------------------------------------------------------------response diff --git a/spec/language_server/definition/location_link/variable_store_state b/spec/language_server/definition/location_link/variable_store_state new file mode 100644 index 000000000..9c05f619f --- /dev/null +++ b/spec/language_server/definition/location_link/variable_store_state @@ -0,0 +1,79 @@ +store Test { + state title : String = "title" + + fun load (text : String) : Promise(Void) { + Promise.never() + } + + fun dashboard : Promise(Void) { + await load(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": 8, + "character": 15 + } + }, + "method": "textDocument/definition" +} +-------------------------------------------------------------------------request +{ + "jsonrpc": "2.0", + "result": { + "originSelectionRange": { + "start": { + "line": 8, + "character": 15 + }, + "end": { + "line": 8, + "character": 20 + } + }, + "targetUri": "file://#{root_path}/test.mint", + "targetRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 32 + } + }, + "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/spec/type_checking/provider_const b/spec/type_checking/provider_const new file mode 100644 index 000000000..8ea67f70b --- /dev/null +++ b/spec/type_checking/provider_const @@ -0,0 +1,24 @@ +record Subscription { + a : Bool +} + +provider Provider : Subscription { + const ONE_PLUS_ONE = 1 + 1 + const TWO = 2 + + fun test : Bool { + ONE_PLUS_ONE == TWO + } +} +-----------------------------------------------------------------VariableMissing +record Subscription { + a : Bool +} + +provider Provider : Subscription { + const TWO = 2 + + fun test : Bool { + 1 + TWO == THREE + } +} diff --git a/src/formatters/provider.cr b/src/formatters/provider.cr index 531f472ad..8d95fd3e1 100644 --- a/src/formatters/provider.cr +++ b/src/formatters/provider.cr @@ -8,7 +8,7 @@ module Mint node.subscription body = - list node.functions + node.comments + node.states + node.gets + list node.functions + node.comments + node.states + node.gets + node.constants comment = node.comment.try { |item| "#{format(item)}\n" } 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/enum_id.cr b/src/ls/definition/enum_id.cr index 9be315861..0b4c91b91 100644 --- a/src/ls/definition/enum_id.cr +++ b/src/ls/definition/enum_id.cr @@ -2,20 +2,39 @@ module Mint module LS class Definition < LSP::RequestMessage def definition(node : Ast::EnumId, server : Server, workspace : Workspace, stack : Array(Ast::Node)) - return unless name = node.name - return unless enum_node = - workspace.ast.enums.find(&.name.value.==(name.value)) + name = node.name - return if Core.ast.enums.includes?(enum_node) + # When `.name` is nil the node is used as a CONSTANT + if name.nil? + stack.each do |parent| + case parent + when Ast::Component, + Ast::Store, + Ast::Suite, + Ast::Module, + Ast::Provider + parent.constants.each do |constant| + if node.option.value == constant.name.value + return location_link server, node.option, constant.name, constant + end + end + end + end + else + return unless enum_node = + workspace.ast.enums.find(&.name.value.==(name.value)) - case - when cursor_intersects?(name) - location_link server, name, enum_node.name, enum_node - when cursor_intersects?(node.option) - return unless option = - enum_node.try &.options.find(&.value.value.==(node.option.value)) + return if Core.ast.enums.includes?(enum_node) - location_link server, node.option, option.value, option + case + when cursor_intersects?(name) + location_link server, name, enum_node.name, enum_node + when cursor_intersects?(node.option) + return unless option = + enum_node.try &.options.find(&.value.value.==(node.option.value)) + + location_link server, node.option, option.value, option + end end end end 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/ls/definition/variable.cr b/src/ls/definition/variable.cr new file mode 100644 index 000000000..8894f9bb8 --- /dev/null +++ b/src/ls/definition/variable.cr @@ -0,0 +1,101 @@ +module Mint + module LS + class Definition < LSP::RequestMessage + def definition(node : Ast::Variable, server : Server, workspace : Workspace, stack : Array(Ast::Node)) + lookup = workspace.type_checker.variables[node]? + + if lookup + variable_lookup_parent(node, lookup[1], server, workspace) || + variable_connect(node, lookup[2], server) || + variable_lookup(node, lookup[0], server) + else + variable_record_key(node, server, workspace, stack) || + variable_next_key(node, server, workspace, stack) + end + end + + def variable_connect(node : Ast::Variable, parents : Array(TypeChecker::Scope::Node), server : Server) + # Check to see if this variable is defined as an Ast::ConnectVariable + # as the `.variables` cache links directly to the stores state/function etc + return unless component = parents.select(Ast::Component).first? + + component.connects.each do |connect| + connect.keys.each do |key| + variable = key.name || key.variable + + if variable.value == node.value + return location_link server, node, variable, connect + end + end + end + end + + def variable_lookup_parent(node : Ast::Variable, target : TypeChecker::Scope::Node, server : Server, workspace : Workspace) + case target + when Tuple(String, TypeChecker::Checkable, Ast::Node) + case variable = target[2] + when Ast::Variable + # For some variables in the .variables` cache, we only have access to the + # target Ast::Variable and not its containing node, so we must search for it + return unless parent = workspace + .ast + .nodes + .select { |other| other.is_a?(Ast::EnumDestructuring) || other.is_a?(Ast::Statement) || other.is_a?(Ast::For) } + .select(&.input.file.==(variable.input.file)) + .find { |other| other.from < variable.from && other.to > variable.to } + + location_link server, node, variable, parent + end + end + end + + def variable_lookup(node : Ast::Variable, target : Ast::Node | TypeChecker::Checkable, server : Server) + case item = target + when Ast::Node + name = case item + when Ast::Property, + Ast::Constant, + Ast::Function, + Ast::State, + Ast::Get, + Ast::Argument + item.name + else + item + end + + location_link server, node, name, item + end + end + + def variable_record_key(node : Ast::Variable, server : Server, workspace : Workspace, stack : Array(Ast::Node)) + case field = stack[1]? + when Ast::RecordField + return unless record_name = workspace.type_checker.record_field_lookup[field]? + + return unless record_definition_field = workspace + .ast + .records + .find(&.name.value.==(record_name)) + .try(&.fields.find(&.key.value.==(node.value))) + + location_link server, node, record_definition_field.key, record_definition_field + end + end + + def variable_next_key(node : Ast::Variable, server : Server, workspace : Workspace, stack : Array(Ast::Node)) + case next_call = stack[3]? + when Ast::NextCall + return unless parent = workspace.type_checker.lookups[next_call] + + return unless state = case parent + when Ast::Provider, Ast::Component, Ast::Store + parent.states.find(&.name.value.==(node.value)) + end + + location_link server, node, state.name, state + end + end + end + end +end diff --git a/src/lsp/protocol/semantic_tokens_client_capabilities.cr b/src/lsp/protocol/semantic_tokens_client_capabilities.cr index a86d46ec2..09349a289 100644 --- a/src/lsp/protocol/semantic_tokens_client_capabilities.cr +++ b/src/lsp/protocol/semantic_tokens_client_capabilities.cr @@ -8,7 +8,7 @@ module LSP # The token types that the client supports. @[JSON::Field(key: "tokenTypes")] - property token_types : Array(String) + property token_types : Array(String)? def initialize(@dynamic_registration = nil, @token_types = nil) end 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/provider.cr b/src/parsers/provider.cr index 74709263e..b247bf75e 100644 --- a/src/parsers/provider.cr +++ b/src/parsers/provider.cr @@ -26,7 +26,7 @@ module Mint opening_bracket: ProviderExpectedOpeningBracket, closing_bracket: ProviderExpectedClosingBracket ) do - items = many { function || state || constant || self.comment } + items = many { function || state || get || constant || self.comment } raise ProviderExpectedBody if items.none?(Ast::Function) diff --git a/src/parsers/type_id.cr b/src/parsers/type_id.cr index 3e251c2b0..d8734533c 100644 --- a/src/parsers/type_id.cr +++ b/src/parsers/type_id.cr @@ -1,6 +1,6 @@ module Mint class Parser - def type_id!(error : SyntaxError.class, track : Bool = true) : Ast::TypeId + def type_id!(error : SyntaxError.class, *, track : Bool = true) : Ast::TypeId start do |start_position| value = gather do char(error, &.ascii_uppercase?) @@ -24,7 +24,7 @@ module Mint end end - def type_id(track : Bool = true) : Ast::TypeId? + def type_id(*, track : Bool = true) : Ast::TypeId? start do |start_position| value = gather do return unless char.ascii_uppercase? @@ -59,9 +59,9 @@ module Mint end end - def type_id(error : SyntaxError.class, track : Bool = true) : Ast::TypeId? + def type_id(error : SyntaxError.class, *, track : Bool = true) : Ast::TypeId? return unless char.ascii_uppercase? - type_id! error, track + type_id! error, track: track 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 diff --git a/src/semantic_tokenizer.cr b/src/semantic_tokenizer.cr index e5c183f7f..c359bfcff 100644 --- a/src/semantic_tokenizer.cr +++ b/src/semantic_tokenizer.cr @@ -17,7 +17,7 @@ module Mint Regexp end - TOKEN_TYPES = TokenType.names.map { |name| name[0].downcase + name[1..] } + TOKEN_TYPES = TokenType.names.map!(&.camelcase(lower: true)) # This represents which token types are used for which node. TOKEN_MAP = { @@ -113,8 +113,8 @@ module Mint def tokenize(ast : Ast) # We add the operators and keywords directly from the AST - ast.operators.each { |(from, to)| add(from, to, TokenType::Operator) } - ast.keywords.each { |(from, to)| add(from, to, TokenType::Keyword) } + ast.operators.each { |(from, to)| add(from, to, :operator) } + ast.keywords.each { |(from, to)| add(from, to, :keyword) } tokenize(ast.nodes) end @@ -130,7 +130,7 @@ module Mint end def tokenize(node : Ast::CssDefinition) - add(node.from, node.from + node.name.size, TokenType::Property) + add(node.from, node.from + node.name.size, :property) end def tokenize(node : Ast::ArrayAccess) @@ -138,14 +138,14 @@ module Mint # implemented remove this case index = node.index when Int64 - add(node.from + 1, node.from + 1 + index.to_s.size, TokenType::Number) + add(node.from + 1, node.from + 1 + index.to_s.size, :number) end end def tokenize(node : Ast::HtmlElement) # The closing tag is not saved only the position to it. node.closing_tag_position.try do |position| - add(position, position + node.tag.value.size, TokenType::Namespace) + add(position, position + node.tag.value.size, :namespace) end add(node.tag, TokenType::Namespace) @@ -153,7 +153,7 @@ module Mint def tokenize(node : Ast::HtmlComponent) node.closing_tag_position.try do |position| - add(position, position + node.component.value.size, TokenType::Type) + add(position, position + node.component.value.size, :type) end end diff --git a/src/type_checker/scope.cr b/src/type_checker/scope.cr index 1567e341d..b692dd8c0 100644 --- a/src/type_checker/scope.cr +++ b/src/type_checker/scope.cr @@ -156,7 +156,7 @@ module Mint node.functions.find(&.name.value.==(variable)) || node.states.find(&.name.value.==(variable)) || node.gets.find(&.name.value.==(variable)) || - node.constants.find(&.name.==(variable)) + node.constants.find(&.name.value.==(variable)) end end