From 9b1e8e1daca6568c04f0ee7b2181c226dad3bc33 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Jun 2022 17:52:56 +0000 Subject: [PATCH 1/6] Bump minitest from 5.16.0 to 5.16.1 Bumps [minitest](https://github.com/seattlerb/minitest) from 5.16.0 to 5.16.1. - [Release notes](https://github.com/seattlerb/minitest/releases) - [Changelog](https://github.com/minitest/minitest/blob/master/History.rdoc) - [Commits](https://github.com/seattlerb/minitest/compare/v5.16.0...v5.16.1) --- updated-dependencies: - dependency-name: minitest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 92ad8d38..116a6547 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,7 +9,7 @@ GEM specs: ast (2.4.2) docile (1.4.0) - minitest (5.16.0) + minitest (5.16.1) parallel (1.22.1) parser (3.1.2.0) ast (~> 2.4.1) From a9ad4b45781a706f48ce4a473307973b0464669a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jun 2022 17:48:46 +0000 Subject: [PATCH 2/6] Bump rubocop from 1.30.1 to 1.31.0 Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.30.1 to 1.31.0. - [Release notes](https://github.com/rubocop/rubocop/releases) - [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop/compare/v1.30.1...v1.31.0) --- updated-dependencies: - dependency-name: rubocop dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 116a6547..a5f6f44a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,7 +18,7 @@ GEM rake (13.0.6) regexp_parser (2.5.0) rexml (3.2.5) - rubocop (1.30.1) + rubocop (1.31.0) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) @@ -36,7 +36,7 @@ GEM simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - unicode-display_width (2.1.0) + unicode-display_width (2.2.0) PLATFORMS arm64-darwin-21 From 2e85a4934e8193c7210c5088225d30dd7f164ffd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 29 Jun 2022 17:37:13 +0000 Subject: [PATCH 3/6] Bump rubocop from 1.31.0 to 1.31.1 Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.31.0 to 1.31.1. - [Release notes](https://github.com/rubocop/rubocop/releases) - [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop/compare/v1.31.0...v1.31.1) --- updated-dependencies: - dependency-name: rubocop dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index a5f6f44a..b1b89bfd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,7 @@ GEM specs: ast (2.4.2) docile (1.4.0) + json (2.6.2) minitest (5.16.1) parallel (1.22.1) parser (3.1.2.0) @@ -18,7 +19,8 @@ GEM rake (13.0.6) regexp_parser (2.5.0) rexml (3.2.5) - rubocop (1.31.0) + rubocop (1.31.1) + json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) From ba2a6e65a546e30169abefca6a407e3d15794813 Mon Sep 17 00:00:00 2001 From: Tony Spataro Date: Sun, 3 Jul 2022 15:51:36 -0700 Subject: [PATCH 4/6] Add inlay hint support per LSP specification. Closes #103. --- lib/syntax_tree/language_server.rb | 27 +++++++++++++---- .../language_server/inlay_hints.rb | 30 ++++++++++++++++--- test/language_server/inlay_hints_test.rb | 6 ++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/lib/syntax_tree/language_server.rb b/lib/syntax_tree/language_server.rb index 31c91f9c..1f06b48e 100644 --- a/lib/syntax_tree/language_server.rb +++ b/lib/syntax_tree/language_server.rb @@ -61,11 +61,19 @@ def run } write(id: id, result: [format(store[uri])]) in { + # official RPC in LSP spec 3.17 + method: "textDocument/inlayHint", + id:, + params: { textDocument: { uri: } } + } + write(id: id, result: inlay_hints(store[uri], false)) + in { + # proprietary RPC (deprecated) between this gem and vscode-syntax-tree method: "textDocument/inlayHints", id:, params: { textDocument: { uri: } } } - write(id: id, result: inlay_hints(store[uri])) + write(id: id, result: inlay_hints(store[uri], true)) in { method: "syntaxTree/visualizing", id:, @@ -85,6 +93,9 @@ def run def capabilities { documentFormattingProvider: true, + inlayHintProvider: { + resolveProvider: false + }, textDocumentSync: { change: 1, openClose: true @@ -108,14 +119,18 @@ def format(source) } end - def inlay_hints(source) + def inlay_hints(source, proprietary) inlay_hints = InlayHints.find(SyntaxTree.parse(source)) serialize = ->(position, text) { { position: position, text: text } } - { - before: inlay_hints.before.map(&serialize), - after: inlay_hints.after.map(&serialize) - } + if proprietary + { + before: inlay_hints.before.map(&serialize), + after: inlay_hints.after.map(&serialize) + } + else + inlay_hints.all + end rescue Parser::ParseError # If there is a parse error, then we're not going to return any inlay # hints for this source. diff --git a/lib/syntax_tree/language_server/inlay_hints.rb b/lib/syntax_tree/language_server/inlay_hints.rb index 089355a7..4be8a765 100644 --- a/lib/syntax_tree/language_server/inlay_hints.rb +++ b/lib/syntax_tree/language_server/inlay_hints.rb @@ -2,18 +2,19 @@ module SyntaxTree class LanguageServer - # This class provides inlay hints for the language server. It is loosely - # designed around the LSP spec, but existed before the spec was finalized so - # is a little different for now. + # This class provides inlay hints for the language server. It existed + # before the spec was finalized so, so it provides two result formats: + # aligned with the spec (`#all`) and proprietary (`#before` and `#after`). # # For more information, see the spec here: # https://github.com/microsoft/language-server-protocol/issues/956. # class InlayHints < Visitor - attr_reader :stack, :before, :after + attr_reader :stack, :all, :before, :after def initialize @stack = [] + @all = [] @before = Hash.new { |hash, key| hash[key] = +"" } @after = Hash.new { |hash, key| hash[key] = +"" } end @@ -98,6 +99,13 @@ def visit_if_op(node) def visit_rescue(node) if node.exception.nil? after[node.location.start_char + "rescue".length] << " StandardError" + all << { + position: { + line: node.location.start_line - 1, + character: node.location.start_column + "rescue".length + }, + label: " StandardError" + } end super @@ -129,6 +137,20 @@ def self.find(program) private def parentheses(location) + all << { + position: { + line: location.start_line - 1, + character: location.start_column + }, + label: "₍" + } + all << { + position: { + line: location.end_line - 1, + character: location.end_column + }, + label: "₎" + } before[location.start_char] << "₍" after[location.end_char] << "₎" end diff --git a/test/language_server/inlay_hints_test.rb b/test/language_server/inlay_hints_test.rb index f652f6d8..35db365a 100644 --- a/test/language_server/inlay_hints_test.rb +++ b/test/language_server/inlay_hints_test.rb @@ -11,6 +11,7 @@ def test_assignments_in_parameters assert_equal(1, hints.before.length) assert_equal(1, hints.after.length) + assert_equal(2, hints.all.length) end def test_operators_in_binaries @@ -18,6 +19,7 @@ def test_operators_in_binaries assert_equal(1, hints.before.length) assert_equal(1, hints.after.length) + assert_equal(2, hints.all.length) end def test_binaries_in_assignments @@ -25,6 +27,7 @@ def test_binaries_in_assignments assert_equal(1, hints.before.length) assert_equal(1, hints.after.length) + assert_equal(2, hints.all.length) end def test_nested_ternaries @@ -32,12 +35,14 @@ def test_nested_ternaries assert_equal(1, hints.before.length) assert_equal(1, hints.after.length) + assert_equal(2, hints.all.length) end def test_bare_rescue hints = find("begin; rescue; end") assert_equal(1, hints.after.length) + assert_equal(1, hints.all.length) end def test_unary_in_binary @@ -45,6 +50,7 @@ def test_unary_in_binary assert_equal(1, hints.before.length) assert_equal(1, hints.after.length) + assert_equal(2, hints.all.length) end private From 0d59abea754f4dcd9919cf1fa5b49b4f5c4fd63e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Jul 2022 17:26:55 +0000 Subject: [PATCH 5/6] Bump minitest from 5.16.1 to 5.16.2 Bumps [minitest](https://github.com/seattlerb/minitest) from 5.16.1 to 5.16.2. - [Release notes](https://github.com/seattlerb/minitest/releases) - [Changelog](https://github.com/minitest/minitest/blob/master/History.rdoc) - [Commits](https://github.com/seattlerb/minitest/compare/v5.16.1...v5.16.2) --- updated-dependencies: - dependency-name: minitest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index b1b89bfd..7ad92e0b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,7 +10,7 @@ GEM ast (2.4.2) docile (1.4.0) json (2.6.2) - minitest (5.16.1) + minitest (5.16.2) parallel (1.22.1) parser (3.1.2.0) ast (~> 2.4.1) From 201d27dce2f0d3149d5a1b7b31448b62cc02d8d0 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 4 Jul 2022 19:39:55 -0400 Subject: [PATCH 6/6] Bump to v2.9.0 --- CHANGELOG.md | 7 ++++++- Gemfile.lock | 2 +- lib/syntax_tree/version.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95d1f92c..2c5e8bbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +## [2.9.0] - 2022-07-04 + +- [#106](https://github.com/ruby-syntax-tree/syntax_tree/pull/106) - Add inlay hint support to match the LSP specification. + ## [2.8.0] - 2022-06-21 ### Added @@ -272,7 +276,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - 🎉 Initial release! 🎉 -[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.8.0...HEAD +[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.1.0...HEAD +[2.1.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.8.0...v2.1.0 [2.8.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.7.1...v2.8.0 [2.7.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.7.0...v2.7.1 [2.7.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.6.0...v2.7.0 diff --git a/Gemfile.lock b/Gemfile.lock index 7ad92e0b..effdb9aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - syntax_tree (2.8.0) + syntax_tree (2.9.0) prettier_print GEM diff --git a/lib/syntax_tree/version.rb b/lib/syntax_tree/version.rb index 881c65aa..5622a4da 100644 --- a/lib/syntax_tree/version.rb +++ b/lib/syntax_tree/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SyntaxTree - VERSION = "2.8.0" + VERSION = "2.9.0" end