Module: Ibex::LSP::DocumentHandlers
Overview
Applies full-text LSP document notifications to the overlay-backed store.
Instance Method Summary
collapse
#hash_member, #integer_member, #params_hash, #publish, #require_running!, #require_state!, #stale_publication?, #store, #string_member, #workspace
Instance Method Details
#did_change(raw_params) ⇒ nil
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/ibex/lsp/document_handlers.rb', line 24
def did_change(raw_params)
require_running!
params = params_hash(raw_params)
document = hash_member(params, "textDocument")
changes = params["contentChanges"]
first_change = changes.is_a?(Array) ? changes.first : nil
unless changes.is_a?(Array) && changes.one? && first_change.is_a?(Hash) &&
!first_change.key?("range") && !first_change.key?("rangeLength")
raise ProtocolError.new("full sync requires exactly one range-free content change", code: -32_602)
end
change = changes.fetch(0) source = string_member(change, "text")
publications = store.change(
string_member(document, "uri"), integer_member(document, "version"), source
)
publish(publications)
nil
end
|
#did_close(raw_params) ⇒ nil
59
60
61
62
63
64
65
|
# File 'lib/ibex/lsp/document_handlers.rb', line 59
def did_close(raw_params)
require_running!
params = params_hash(raw_params)
document = hash_member(params, "textDocument")
publish(store.close(string_member(document, "uri")))
nil
end
|
#did_open(raw_params) ⇒ nil
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/ibex/lsp/document_handlers.rb', line 12
def did_open(raw_params)
require_running!
params = params_hash(raw_params)
document = hash_member(params, "textDocument")
publications = store.open(
string_member(document, "uri"), integer_member(document, "version"), string_member(document, "text")
)
publish(publications)
nil
end
|
#did_save(raw_params) ⇒ nil
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ibex/lsp/document_handlers.rb', line 45
def did_save(raw_params)
require_running!
params = params_hash(raw_params)
document = hash_member(params, "textDocument")
source = params["text"]
unless source.nil? || source.is_a?(String)
raise ProtocolError.new("saved document text must be a string", code: -32_602)
end
publish(store.save(string_member(document, "uri"), source: source))
nil
end
|