Skip to content

Commit

Permalink
Ensure returned uri from code actions contain a scheme
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimnanney committed Jul 16, 2024
1 parent 30fec01 commit 2fcca8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 8 additions & 2 deletions lib/standard/lsp/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 : []
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions test/standard/runners/lsp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down

0 comments on commit 2fcca8d

Please sign in to comment.