From 2fcca8d4d060b1cc3daf7dc86227b397b86ab6d3 Mon Sep 17 00:00:00 2001 From: Jim Nanney Date: Tue, 16 Jul 2024 09:59:21 -0500 Subject: [PATCH] Ensure returned uri from code actions contain a scheme Using Neovim 0.10 with the ruby-lsp plugin, standard returns code actions to allow for quick fixes. They were returning the uri without the scheme, and that caused neovim to give an error. To correct for the error, I added an ensure_uri_scheme method to parse the uri and add the "file" scheme if the uri did not include one. --- lib/standard/lsp/diagnostic.rb | 10 ++++++++-- test/standard/runners/lsp_test.rb | 12 ++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/standard/lsp/diagnostic.rb b/lib/standard/lsp/diagnostic.rb index 77f86387..260e8152 100644 --- a/lib/standard/lsp/diagnostic.rb +++ b/lib/standard/lsp/diagnostic.rb @@ -82,7 +82,7 @@ def autocorrect_action document_changes: [ Interface::TextDocumentEdit.new( text_document: Interface::OptionalVersionedTextDocumentIdentifier.new( - uri: @uri.to_s, + uri: ensure_uri_scheme(@uri.to_s).to_s, version: nil ), edits: correctable? ? offense_replacements : [] @@ -113,7 +113,7 @@ def disable_line_action document_changes: [ Interface::TextDocumentEdit.new( text_document: Interface::OptionalVersionedTextDocumentIdentifier.new( - uri: @uri.to_s, + uri: ensure_uri_scheme(@uri.to_s).to_s, version: nil ), edits: line_disable_comment @@ -163,6 +163,12 @@ def length_of_line(line) def correctable? !@offense.corrector.nil? end + + def ensure_uri_scheme(uri) + uri = URI.parse(uri) + uri.scheme = "file" if uri.scheme.nil? + uri + end end end end diff --git a/test/standard/runners/lsp_test.rb b/test/standard/runners/lsp_test.rb index e6adf3aa..d9fb7a62 100644 --- a/test/standard/runners/lsp_test.rb +++ b/test/standard/runners/lsp_test.rb @@ -65,7 +65,7 @@ def test_did_open edit: { documentChanges: [ { - textDocument: {uri: "/path/to/file.rb", version: nil}, + textDocument: {uri: "file:///path/to/file.rb", version: nil}, edits: [ { range: { @@ -84,7 +84,7 @@ def test_did_open edit: { documentChanges: [ { - textDocument: {uri: "/path/to/file.rb", version: nil}, + textDocument: {uri: "file:///path/to/file.rb", version: nil}, edits: [ { range: { @@ -120,7 +120,7 @@ def test_did_open edit: { documentChanges: [ { - textDocument: {uri: "/path/to/file.rb", version: nil}, + textDocument: {uri: "file:///path/to/file.rb", version: nil}, edits: [ { range: { @@ -139,7 +139,7 @@ def test_did_open edit: { documentChanges: [ { - textDocument: {uri: "/path/to/file.rb", version: nil}, + textDocument: {uri: "file:///path/to/file.rb", version: nil}, edits: [ { range: { @@ -176,7 +176,7 @@ def test_did_open edit: { documentChanges: [ { - textDocument: {uri: "/path/to/file.rb", version: nil}, + textDocument: {uri: "file:///path/to/file.rb", version: nil}, edits: [ { range: { @@ -196,7 +196,7 @@ def test_did_open edit: { documentChanges: [ { - textDocument: {uri: "/path/to/file.rb", version: nil}, + textDocument: {uri: "file:///path/to/file.rb", version: nil}, edits: [ { range: {