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: {