Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,21 @@ def text_document_did_open(message)
),
)
end

# Documents are parsed on creation, so the virtual state would otherwise only be sent after the first edit
if document.is_a?(ERBDocument) && @global_state.client_capabilities.supports_request_delegation
send_message(
Notification.new(
method: "delegate/textDocument/virtualState",
params: {
textDocument: {
uri: text_document[:uri].to_s,
text: document.host_language_source,
},
},
),
)
end
end

#: (Hash[Symbol, untyped] message) -> void
Expand Down
22 changes: 22 additions & 0 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,28 @@ def test_does_not_crash_when_a_document_uri_cannot_be_parsed
server&.run_shutdown
end

def test_did_open_sends_the_virtual_state_of_erb_documents
@server.global_state.apply_options({ capabilities: { experimental: { requestDelegation: true } } })
uri = URI("file:///foo.html.erb")

@server.process_message({
method: "textDocument/didOpen",
params: {
textDocument: {
uri: uri,
text: "<div><%= foo %></div>",
version: 1,
languageId: "erb",
},
},
})

notification = find_message(RubyLsp::Notification, "delegate/textDocument/virtualState")
document = @server.instance_variable_get(:@store).get(uri)
assert_equal(uri.to_s, notification.params[:textDocument][:uri])
assert_equal(document.host_language_source, notification.params[:textDocument][:text])
end

private

def run_initialize_server_with_setup_error(error)
Expand Down
Loading