Skip to content

Commit 08d7280

Browse files
committed
feat: add a "publish all diagnostics" mode for LSP
This is ad-hoc. I need to implement more fine-grained diagnostics publishing...
1 parent 1e16f55 commit 08d7280

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

lib/typeprof/lsp/messages.rb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,6 @@ def notify(method, **params)
2828
@server.send_notification(method, **params)
2929
end
3030

31-
def publish_diagnostics(uri)
32-
text = @server.open_texts[uri]
33-
diags = []
34-
if text
35-
@server.core.diagnostics(text.path) do |diag|
36-
diags << diag.to_lsp
37-
end
38-
end
39-
notify(
40-
"textDocument/publishDiagnostics",
41-
uri: uri,
42-
diagnostics: diags
43-
)
44-
end
45-
4631
Classes = []
4732
def self.inherited(klass)
4833
Classes << klass
@@ -153,7 +138,7 @@ def run
153138
@server.open_texts[uri] = text
154139
@server.core.update_file(text.path, text.string)
155140
@server.send_request("workspace/codeLens/refresh")
156-
publish_diagnostics(uri)
141+
@server.publish_diagnostics(uri)
157142
end
158143
end
159144

@@ -166,7 +151,7 @@ def run
166151
text.apply_changes(changes, version)
167152
@server.core.update_file(text.path, text.string)
168153
@server.send_request("workspace/codeLens/refresh")
169-
publish_diagnostics(uri)
154+
@server.publish_diagnostics(uri)
170155
end
171156
end
172157

lib/typeprof/lsp/server.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def self.start_socket(core)
4444
end
4545
end
4646

47-
def initialize(core, reader, writer, url_schema: nil)
47+
def initialize(core, reader, writer, url_schema: nil, publish_all_diagnostics: false)
4848
@core = core
4949
@workspaces = {}
5050
@reader = reader
@@ -56,6 +56,7 @@ def initialize(core, reader, writer, url_schema: nil)
5656
@exit = false
5757
@signature_enabled = true
5858
@url_schema = url_schema || (File::ALT_SEPARATOR != "\\" ? "file://" : "file:///")
59+
@publish_all_diagnostics = publish_all_diagnostics # TODO: implement more dedicated publish feature
5960
end
6061

6162
attr_reader :core, :open_texts
@@ -145,6 +146,22 @@ def cancel_request(id)
145146
def exit
146147
@exit = true
147148
end
149+
150+
def publish_diagnostics(uri)
151+
(@publish_all_diagnostics ? @open_texts : [[uri, @open_texts[uri]]]).each do |uri, text|
152+
diags = []
153+
if text
154+
@core.diagnostics(text.path) do |diag|
155+
diags << diag.to_lsp
156+
end
157+
end
158+
send_notification(
159+
"textDocument/publishDiagnostics",
160+
uri: uri,
161+
diagnostics: diags
162+
)
163+
end
164+
end
148165
end
149166

150167
class Reader

0 commit comments

Comments
 (0)