Skip to content

Commit b2ea747

Browse files
committed
refactor(lsp): split long function into parsing func + logic func
1 parent f052bbc commit b2ea747

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/quick-lint-js/lsp/lsp-server.cpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,28 +339,39 @@ void linting_lsp_server_handler::handle_text_document_did_change_notification(
339339
return;
340340
}
341341

342-
auto document_it = this->documents_.find(string8(uri->data));
342+
::simdjson::ondemand::array changes;
343+
if (!get_array(request, "params", "contentChanges", &changes)) {
344+
// Ignore invalid notification.
345+
return;
346+
}
347+
348+
return this->handle_text_document_did_change_notification(
349+
lsp_text_document_did_change_notification{
350+
.uri = *uri,
351+
.version_json = get_raw_json(version),
352+
.changes = changes,
353+
});
354+
}
355+
356+
void linting_lsp_server_handler::handle_text_document_did_change_notification(
357+
const lsp_text_document_did_change_notification& notification) {
358+
auto document_it = this->documents_.find(string8(notification.uri.data));
343359
bool url_is_tracked = document_it != this->documents_.end();
344360
if (!url_is_tracked) {
345361
return;
346362
}
347363
document_base& doc = *document_it->second;
348364

349-
std::string document_path = parse_file_from_lsp_uri(uri->data);
365+
std::string document_path = parse_file_from_lsp_uri(notification.uri.data);
350366
if (document_path.empty()) {
351367
// TODO(strager): Report a warning and use a default configuration.
352368
QLJS_UNIMPLEMENTED();
353369
}
354370

355-
::simdjson::ondemand::array changes;
356-
if (!get_array(request, "params", "contentChanges", &changes)) {
357-
// Ignore invalid notification.
358-
return;
359-
}
360-
this->apply_document_changes(doc.doc, changes);
361-
doc.version_json = get_raw_json(version);
371+
this->apply_document_changes(doc.doc, notification.changes);
372+
doc.version_json = notification.version_json;
362373

363-
doc.on_text_changed(*this, uri->json);
374+
doc.on_text_changed(*this, notification.uri.json);
364375
}
365376

366377
void linting_lsp_server_handler::config_document::on_text_changed(

src/quick-lint-js/lsp/lsp-server.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,16 @@ class linting_lsp_server_handler final : public lsp_endpoint_handler {
158158
::simdjson::ondemand::value& result);
159159

160160
void handle_initialized_notification();
161+
162+
struct lsp_text_document_did_change_notification {
163+
string_json_token uri;
164+
string8_view version_json;
165+
::simdjson::ondemand::array& changes;
166+
};
161167
void handle_text_document_did_change_notification(
162168
::simdjson::ondemand::object& request);
169+
void handle_text_document_did_change_notification(
170+
const lsp_text_document_did_change_notification& notification);
163171

164172
struct lsp_text_document_did_close_notification {
165173
string8_view uri;

0 commit comments

Comments
 (0)