@jbearak/sight 0.13.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,7 +52,7 @@ var package_default;
52
52
  var init_package = __esm(() => {
53
53
  package_default = {
54
54
  name: "@jbearak/sight",
55
- version: "0.13.0",
55
+ version: "0.14.1",
56
56
  type: "module",
57
57
  workspaces: [
58
58
  "client"
@@ -20708,6 +20708,19 @@ async function with_parse_timeout(operation, timeout_ms = PARSE_TIMEOUT_MS) {
20708
20708
  }
20709
20709
  var PARSE_TIMEOUT_MS = 5000;
20710
20710
 
20711
+ // src/utils/polling-cancellation-token.ts
20712
+ function polling_cancellation_token(should_continue, parent) {
20713
+ return {
20714
+ get isCancellationRequested() {
20715
+ return parent?.isCancellationRequested === true || !should_continue();
20716
+ },
20717
+ onCancellationRequested: no_op_cancellation_event
20718
+ };
20719
+ }
20720
+ var no_op_cancellation_event = () => ({ dispose: () => {
20721
+ return;
20722
+ } });
20723
+
20711
20724
  // src/document-store.ts
20712
20725
  import * as fs4 from "fs";
20713
20726
  import * as path4 from "path";
@@ -20775,7 +20788,7 @@ class DocumentStore {
20775
20788
  throw new Error("DocumentStore has been disposed");
20776
20789
  }
20777
20790
  }
20778
- async open(uri, content, version, workspace_symbols, scope_resolver_config) {
20791
+ async open(uri, content, version, workspace_symbols, scope_resolver_config, is_operation_current) {
20779
20792
  this.check_disposed();
20780
20793
  const generation = (this.generations.get(uri) ?? 0) + 1;
20781
20794
  this.generations.set(uri, generation);
@@ -20790,9 +20803,15 @@ class DocumentStore {
20790
20803
  if (this.disposed) {
20791
20804
  return;
20792
20805
  }
20806
+ if (is_operation_current && !is_operation_current()) {
20807
+ return;
20808
+ }
20793
20809
  this.evict_if_needed(content.length);
20794
- const outcome = await this.create_document_state(uri, content, version, workspace_symbols, scope_resolver_config);
20795
- this.commit_state(uri, outcome, generation);
20810
+ const outcome = await this.create_document_state(uri, content, version, workspace_symbols, scope_resolver_config, is_operation_current);
20811
+ if (!outcome) {
20812
+ return;
20813
+ }
20814
+ this.commit_state(uri, outcome, generation, is_operation_current);
20796
20815
  };
20797
20816
  const promise = operation();
20798
20817
  this.active_updates.set(uri, promise);
@@ -20805,7 +20824,7 @@ class DocumentStore {
20805
20824
  this.decrement_in_flight(uri);
20806
20825
  }
20807
20826
  }
20808
- async update(uri, changes, version, workspace_symbols, scope_resolver_config) {
20827
+ async update(uri, changes, version, workspace_symbols, scope_resolver_config, is_operation_current) {
20809
20828
  this.check_disposed();
20810
20829
  const generation = (this.generations.get(uri) ?? 0) + 1;
20811
20830
  this.generations.set(uri, generation);
@@ -20820,6 +20839,9 @@ class DocumentStore {
20820
20839
  if (this.disposed) {
20821
20840
  return;
20822
20841
  }
20842
+ if (is_operation_current && !is_operation_current()) {
20843
+ return;
20844
+ }
20823
20845
  const state = this.documents.get(uri);
20824
20846
  if (!state) {
20825
20847
  return;
@@ -20840,8 +20862,11 @@ class DocumentStore {
20840
20862
  this.metrics.cache_hits++;
20841
20863
  return;
20842
20864
  }
20843
- const new_outcome = await this.create_document_state(uri, new_content, version, workspace_symbols, scope_resolver_config);
20844
- this.commit_state(uri, new_outcome, generation);
20865
+ const new_outcome = await this.create_document_state(uri, new_content, version, workspace_symbols, scope_resolver_config, is_operation_current);
20866
+ if (!new_outcome) {
20867
+ return;
20868
+ }
20869
+ this.commit_state(uri, new_outcome, generation, is_operation_current);
20845
20870
  };
20846
20871
  const promise = operation();
20847
20872
  this.active_updates.set(uri, promise);
@@ -20884,10 +20909,13 @@ class DocumentStore {
20884
20909
  get_metrics() {
20885
20910
  return { ...this.metrics };
20886
20911
  }
20887
- commit_state(uri, outcome, generation) {
20912
+ commit_state(uri, outcome, generation, is_operation_current) {
20888
20913
  if (this.disposed) {
20889
20914
  return false;
20890
20915
  }
20916
+ if (is_operation_current && !is_operation_current()) {
20917
+ return false;
20918
+ }
20891
20919
  const closed_gen = this.closed_generations.get(uri);
20892
20920
  if (closed_gen !== undefined && generation <= closed_gen) {
20893
20921
  return false;
@@ -20932,11 +20960,11 @@ class DocumentStore {
20932
20960
  return;
20933
20961
  }
20934
20962
  }
20935
- async recover_staged_effects_with_timeout(content, uri, scope_resolver_config) {
20963
+ async recover_staged_effects_with_timeout(content, uri, scope_resolver_config, is_operation_current) {
20936
20964
  try {
20937
20965
  const my_directive_parser = new DirectiveParser;
20938
- const my_result = await with_parse_timeout(() => my_directive_parser.parse(content, uri));
20939
- if (!my_result.success || my_result.timed_out || !my_result.result) {
20966
+ const my_result = await with_parse_timeout(() => is_operation_current?.() === false ? null : my_directive_parser.parse(content, uri));
20967
+ if (is_operation_current?.() === false || !my_result.success || my_result.timed_out || !my_result.result) {
20940
20968
  return;
20941
20969
  }
20942
20970
  return this.stage_cross_file_effects(my_result.result, scope_resolver_config);
@@ -21053,16 +21081,24 @@ class DocumentStore {
21053
21081
  }
21054
21082
  return total;
21055
21083
  }
21056
- async create_document_state(uri, content, version, workspace_symbols, scope_resolver_config) {
21084
+ async create_document_state(uri, content, version, workspace_symbols, scope_resolver_config, is_operation_current) {
21057
21085
  const start_time = Date.now();
21058
21086
  this.metrics.parse_count++;
21087
+ const operation_is_current = () => is_operation_current?.() !== false;
21088
+ const cancellation_token = is_operation_current ? polling_cancellation_token(is_operation_current) : undefined;
21059
21089
  const lexer = new StataLexer;
21060
21090
  const parser = new StataParser;
21061
21091
  const analyzer = new SemanticAnalyzer;
21062
21092
  const effective_scope_resolver_config = scope_resolver_config ?? this.scope_resolver_config;
21063
- const lex_result = await with_parse_timeout(() => lexer.tokenize(content));
21093
+ const lex_result = await with_parse_timeout(() => operation_is_current() ? lexer.tokenize(content) : null);
21094
+ if (!operation_is_current() || lex_result.result === null) {
21095
+ return;
21096
+ }
21064
21097
  if (!lex_result.success || lex_result.timed_out) {
21065
- const recovered_staged_effects = lex_result.timed_out ? undefined : await this.recover_staged_effects_with_timeout(content, uri, effective_scope_resolver_config);
21098
+ const recovered_staged_effects = lex_result.timed_out ? undefined : await this.recover_staged_effects_with_timeout(content, uri, effective_scope_resolver_config, is_operation_current);
21099
+ if (!operation_is_current()) {
21100
+ return;
21101
+ }
21066
21102
  return {
21067
21103
  state: this.create_error_state(uri, content, version, lex_result.error || "Lexer timeout", lex_result.result?.line_offsets),
21068
21104
  staged_effects: recovered_staged_effects
@@ -21072,7 +21108,10 @@ class DocumentStore {
21072
21108
  my_context_tracker.initialize_from_tokens(lex_result.result.tokens, content);
21073
21109
  const context_ranges = my_context_tracker.get_all_context_ranges();
21074
21110
  this.assert_ranges_sorted(context_ranges);
21075
- const parse_result = await with_parse_timeout(() => parser.parse(lex_result.result.tokens, my_context_tracker));
21111
+ const parse_result = await with_parse_timeout(() => operation_is_current() ? parser.parse(lex_result.result.tokens, my_context_tracker) : null);
21112
+ if (!operation_is_current() || parse_result.result === null) {
21113
+ return;
21114
+ }
21076
21115
  if (!parse_result.success || parse_result.timed_out) {
21077
21116
  const recovered_staged_effects = this.recover_staged_effects_from_tokens(content, uri, lex_result.result.tokens, effective_scope_resolver_config);
21078
21117
  return {
@@ -21090,16 +21129,22 @@ class DocumentStore {
21090
21129
  resolved_working_directory = this.resolve_working_directory(directive_result.working_directory, uri);
21091
21130
  } else if (this.scope_resolver) {
21092
21131
  try {
21093
- const scope_result = await this.scope_resolver.resolve(uri, content, effective_scope_resolver_config, undefined, { register_dependencies: false });
21132
+ const scope_result = await this.scope_resolver.resolve(uri, content, effective_scope_resolver_config, cancellation_token, { register_dependencies: false });
21094
21133
  if (scope_result.inherited_working_directory) {
21095
21134
  resolved_working_directory = scope_result.inherited_working_directory;
21096
21135
  }
21097
21136
  } catch {}
21098
21137
  }
21099
21138
  } catch {}
21100
- const analyze_result = await with_parse_timeout(() => analyzer.analyze(parse_result.result.ast, uri, workspace_symbols, {
21139
+ if (!operation_is_current()) {
21140
+ return;
21141
+ }
21142
+ const analyze_result = await with_parse_timeout(() => operation_is_current() ? analyzer.analyze(parse_result.result.ast, uri, workspace_symbols, {
21101
21143
  working_directory: resolved_working_directory
21102
- }, lex_result.result.tokens));
21144
+ }, lex_result.result.tokens) : null);
21145
+ if (!operation_is_current() || analyze_result.result === null) {
21146
+ return;
21147
+ }
21103
21148
  const elapsed_ms = Date.now() - start_time;
21104
21149
  this.metrics.parse_total_ms += elapsed_ms;
21105
21150
  if (!analyze_result.success || analyze_result.timed_out) {
@@ -23089,22 +23134,23 @@ class ScopeResolver {
23089
23134
  used_auto_parents: has_auto_parents
23090
23135
  } = this.get_effective_backward_directives(file_uri, my_directives, my_config, is_standalone);
23091
23136
  const scan_complete_at_resolve_time = this.dependency_graph?.is_scan_complete();
23137
+ const cancelled_scope = () => ({
23138
+ chain: the_chain,
23139
+ symbols: create_empty_symbol_table(),
23140
+ out_of_scope_symbols: the_out_of_scope,
23141
+ diagnostics: [],
23142
+ has_directives,
23143
+ has_auto_parents,
23144
+ is_standalone,
23145
+ scan_complete_at_resolve_time
23146
+ });
23092
23147
  const normalized_directives = this.normalize_directives(effective_directives, the_diagnostics);
23093
23148
  if (options?.register_dependencies ?? true) {
23094
23149
  this.apply_normalized_backward_directives(file_uri, normalized_directives);
23095
23150
  }
23096
23151
  const directive_result = await this.follow_directives(normalized_directives, file_uri, visited, the_chain, the_diagnostics, the_out_of_scope, 1, my_config, request_cache, token);
23097
23152
  if (token?.isCancellationRequested) {
23098
- return {
23099
- chain: the_chain,
23100
- symbols: create_empty_symbol_table(),
23101
- out_of_scope_symbols: the_out_of_scope,
23102
- diagnostics: [],
23103
- has_directives,
23104
- has_auto_parents,
23105
- is_standalone,
23106
- scan_complete_at_resolve_time
23107
- };
23153
+ return cancelled_scope();
23108
23154
  }
23109
23155
  const merged_symbols = this.merge_chain(the_chain);
23110
23156
  let own_working_directory;
@@ -23138,6 +23184,9 @@ class ScopeResolver {
23138
23184
  max_depth: my_config.diagnostics?.max_depth
23139
23185
  }
23140
23186
  });
23187
+ if (token?.isCancellationRequested) {
23188
+ return cancelled_scope();
23189
+ }
23141
23190
  if (forward_result.call_sites.length > 0) {
23142
23191
  forward_call_symbols = forward_result.call_sites;
23143
23192
  }
@@ -29087,49 +29136,83 @@ var init_literal_macro_adjacency_diagnostics = __esm(() => {
29087
29136
 
29088
29137
  // src/providers/diagnostics-publish-gate.ts
29089
29138
  class DiagnosticsPublishGate {
29090
- last_published_version = new Map;
29091
- last_published_epoch = new Map;
29092
- current_epoch = new Map;
29093
- get_current_epoch(uri) {
29094
- return this.current_epoch.get(uri) ?? 0;
29095
- }
29096
- would_publish(uri, version, epoch) {
29097
- const my_last_version = this.last_published_version.get(uri);
29098
- if (my_last_version === undefined || version > my_last_version) {
29099
- return true;
29139
+ lifecycle_by_uri = new Map;
29140
+ next_lifecycle_epoch = 0;
29141
+ begin_lifecycle(uri, version) {
29142
+ const state = {
29143
+ lifecycle_epoch: this.next_lifecycle_epoch++,
29144
+ document_version: version,
29145
+ force_epoch: 0
29146
+ };
29147
+ this.lifecycle_by_uri.set(uri, state);
29148
+ return this.trigger_from(state);
29149
+ }
29150
+ trigger_for_validation(uri, version) {
29151
+ const state = this.lifecycle_by_uri.get(uri);
29152
+ if (!state) {
29153
+ return;
29100
29154
  }
29101
- if (version < my_last_version) {
29102
- return false;
29155
+ if (version > state.document_version) {
29156
+ state.document_version = version;
29103
29157
  }
29104
- const my_current_epoch = this.current_epoch.get(uri) ?? 0;
29105
- const my_last_epoch = this.last_published_epoch.get(uri) ?? 0;
29106
- return epoch === my_current_epoch && epoch > my_last_epoch;
29158
+ return {
29159
+ lifecycle_epoch: state.lifecycle_epoch,
29160
+ document_version: version,
29161
+ force_epoch: state.force_epoch
29162
+ };
29163
+ }
29164
+ is_current_trigger(uri, trigger) {
29165
+ return !!trigger && !!this.state_for_trigger(uri, trigger);
29107
29166
  }
29108
- try_consume_publish(uri, version, epoch) {
29109
- const my_last_version = this.last_published_version.get(uri);
29110
- if (my_last_version === undefined || version > my_last_version) {
29111
- this.last_published_version.set(uri, version);
29112
- this.last_published_epoch.set(uri, epoch);
29167
+ would_publish(uri, version, trigger) {
29168
+ const state = this.state_for_trigger(uri, trigger);
29169
+ if (!state || version !== trigger.document_version) {
29170
+ return false;
29171
+ }
29172
+ if (state.last_published_version === undefined || version > state.last_published_version) {
29113
29173
  return true;
29114
29174
  }
29115
- if (version < my_last_version) {
29175
+ if (version < state.last_published_version) {
29116
29176
  return false;
29117
29177
  }
29118
- const my_current_epoch = this.current_epoch.get(uri) ?? 0;
29119
- const my_last_epoch = this.last_published_epoch.get(uri) ?? 0;
29120
- if (epoch === my_current_epoch && epoch > my_last_epoch) {
29121
- this.last_published_epoch.set(uri, epoch);
29122
- return true;
29178
+ return trigger.force_epoch > (state.last_published_force_epoch ?? -1);
29179
+ }
29180
+ try_consume_publish(uri, version, trigger) {
29181
+ if (!this.would_publish(uri, version, trigger)) {
29182
+ return false;
29123
29183
  }
29124
- return false;
29184
+ const state = this.lifecycle_by_uri.get(uri);
29185
+ state.last_published_version = version;
29186
+ state.last_published_force_epoch = trigger.force_epoch;
29187
+ return true;
29125
29188
  }
29126
29189
  mark_force_republish(uri) {
29127
- this.current_epoch.set(uri, (this.current_epoch.get(uri) ?? 0) + 1);
29190
+ const state = this.lifecycle_by_uri.get(uri);
29191
+ if (!state) {
29192
+ return false;
29193
+ }
29194
+ state.force_epoch++;
29195
+ return true;
29196
+ }
29197
+ retire_lifecycle(uri) {
29198
+ this.lifecycle_by_uri.delete(uri);
29199
+ }
29200
+ retire_all_lifecycles() {
29201
+ this.lifecycle_by_uri.clear();
29128
29202
  }
29129
- forget(uri) {
29130
- this.last_published_version.delete(uri);
29131
- this.last_published_epoch.delete(uri);
29132
- this.current_epoch.delete(uri);
29203
+ trigger_from(state) {
29204
+ return {
29205
+ lifecycle_epoch: state.lifecycle_epoch,
29206
+ document_version: state.document_version,
29207
+ force_epoch: state.force_epoch
29208
+ };
29209
+ }
29210
+ state_for_trigger(uri, trigger) {
29211
+ const state = this.lifecycle_by_uri.get(uri);
29212
+ if (!state || state.lifecycle_epoch !== trigger.lifecycle_epoch || state.document_version !== trigger.document_version || state.force_epoch !== trigger.force_epoch) {
29213
+ return;
29214
+ }
29215
+ return state;
29133
29216
  }
29134
29217
  }
29135
29218
 
@@ -29167,6 +29250,7 @@ class DiagnosticsProvider {
29167
29250
  dependency_graph;
29168
29251
  publish_gate = new DiagnosticsPublishGate;
29169
29252
  filtered_cache = new Map;
29253
+ cache_generation = 0;
29170
29254
  constructor(connection, debounce_manager) {
29171
29255
  this.connection = connection;
29172
29256
  this.debounce_manager = debounce_manager || null;
@@ -29182,25 +29266,41 @@ class DiagnosticsProvider {
29182
29266
  set_debounce_manager(debounce_manager) {
29183
29267
  this.debounce_manager = debounce_manager;
29184
29268
  }
29269
+ on_document_opened(uri, version) {
29270
+ this.publish_gate.begin_lifecycle(uri, version);
29271
+ this.clear_cache_for_document(uri);
29272
+ }
29273
+ trigger_for_validation(uri, version) {
29274
+ return this.publish_gate.trigger_for_validation(uri, version);
29275
+ }
29276
+ is_validation_current(uri, trigger) {
29277
+ return this.publish_gate.is_current_trigger(uri, trigger);
29278
+ }
29185
29279
  mark_force_republish(uri) {
29186
29280
  this.publish_gate.mark_force_republish(uri);
29187
- this.filtered_cache.delete(uri);
29281
+ this.clear_cache_for_document(uri);
29188
29282
  }
29189
- async publish_diagnostics(document, config, workspace_symbols, scope_resolver, cancellation_token) {
29190
- const my_epoch = this.publish_gate.get_current_epoch(document.uri);
29191
- if (!this.publish_gate.would_publish(document.uri, document.version, my_epoch)) {
29283
+ async publish_diagnostics(document, config, diagnostics_trigger, workspace_symbols, scope_resolver, cancellation_token) {
29284
+ if (!this.publish_gate.would_publish(document.uri, document.version, diagnostics_trigger)) {
29285
+ return { diagnostics: [], pending: false };
29286
+ }
29287
+ const computation_token = polling_cancellation_token(() => this.publish_gate.is_current_trigger(document.uri, diagnostics_trigger), cancellation_token);
29288
+ if (computation_token.isCancellationRequested) {
29192
29289
  return { diagnostics: [], pending: false };
29193
29290
  }
29194
29291
  if (!config?.diagnostics?.enabled) {
29195
- if (!this.publish_gate.try_consume_publish(document.uri, document.version, my_epoch)) {
29292
+ if (!this.publish_gate.try_consume_publish(document.uri, document.version, diagnostics_trigger)) {
29196
29293
  return { diagnostics: [], pending: false };
29197
29294
  }
29198
29295
  this.clear_diagnostics(document.uri);
29199
29296
  return { diagnostics: [], pending: false };
29200
29297
  }
29201
29298
  const is_pending = this.debounce_manager?.is_pending(document.uri) ?? false;
29202
- const the_diagnostics = await this.get_diagnostics(document, config, workspace_symbols, scope_resolver, cancellation_token);
29203
- if (!this.publish_gate.try_consume_publish(document.uri, document.version, my_epoch)) {
29299
+ const the_diagnostics = await this.get_diagnostics(document, config, workspace_symbols, scope_resolver, computation_token);
29300
+ if (computation_token.isCancellationRequested) {
29301
+ return { diagnostics: [], pending: is_pending };
29302
+ }
29303
+ if (!this.publish_gate.try_consume_publish(document.uri, document.version, diagnostics_trigger)) {
29204
29304
  return { diagnostics: [], pending: is_pending };
29205
29305
  }
29206
29306
  this.connection.sendDiagnostics({
@@ -29210,7 +29310,10 @@ class DiagnosticsProvider {
29210
29310
  return { diagnostics: the_diagnostics, pending: is_pending };
29211
29311
  }
29212
29312
  async get_diagnostics(document, config, workspace_symbols, scope_resolver, cancellation_token) {
29213
- const cache_epoch_at_start = this.publish_gate.get_current_epoch(document.uri);
29313
+ if (cancellation_token?.isCancellationRequested) {
29314
+ return [];
29315
+ }
29316
+ const cache_generation_at_start = this.cache_generation;
29214
29317
  const config_hash = this.compute_config_hash(config);
29215
29318
  const uri_cache = this.filtered_cache.get(document.uri);
29216
29319
  const inner_key = `${document.version}:${config_hash}`;
@@ -29241,6 +29344,9 @@ class DiagnosticsProvider {
29241
29344
  }
29242
29345
  const my_resolve_config = scope_resolver_config_for(config);
29243
29346
  const resolved_scope = scope_resolver ? await scope_resolver.resolve(document.uri, document.content, my_resolve_config, cancellation_token) : undefined;
29347
+ if (cancellation_token?.isCancellationRequested) {
29348
+ return [];
29349
+ }
29244
29350
  const backward_dep_mode = config.cross_file?.backward_dependencies ?? "auto";
29245
29351
  const scan_complete_for_deferral = resolved_scope?.scan_complete_at_resolve_time ?? false;
29246
29352
  const defer_undefined_diagnostics = backward_dep_mode === "auto" && this.dependency_graph && !scan_complete_for_deferral && resolved_scope && !resolved_scope.has_directives && !resolved_scope.has_auto_parents && !resolved_scope.is_standalone;
@@ -29404,7 +29510,7 @@ class DiagnosticsProvider {
29404
29510
  }
29405
29511
  }
29406
29512
  }
29407
- if (this.publish_gate.get_current_epoch(document.uri) === cache_epoch_at_start) {
29513
+ if (this.cache_generation === cache_generation_at_start) {
29408
29514
  let cache_for_uri = this.filtered_cache.get(document.uri);
29409
29515
  if (!cache_for_uri) {
29410
29516
  cache_for_uri = new Map;
@@ -29486,12 +29592,21 @@ class DiagnosticsProvider {
29486
29592
  }
29487
29593
  clear_cache_for_document(uri) {
29488
29594
  this.filtered_cache.delete(uri);
29595
+ this.cache_generation++;
29489
29596
  }
29490
- on_document_closed(uri) {
29491
- this.publish_gate.forget(uri);
29597
+ on_document_hidden(uri) {
29598
+ this.publish_gate.retire_lifecycle(uri);
29492
29599
  this.clear_cache_for_document(uri);
29493
29600
  this.clear_diagnostics(uri);
29494
29601
  }
29602
+ on_document_closed(uri) {
29603
+ this.on_document_hidden(uri);
29604
+ }
29605
+ on_shutdown() {
29606
+ this.publish_gate.retire_all_lifecycles();
29607
+ this.filtered_cache.clear();
29608
+ this.cache_generation++;
29609
+ }
29495
29610
  convert_lexer_error(error, config) {
29496
29611
  let severity;
29497
29612
  switch (error.code) {
@@ -31287,11 +31402,15 @@ function detect_command_path_context(text_before_cursor) {
31287
31402
  if (text_before_cursor.includes(",")) {
31288
31403
  return null;
31289
31404
  }
31290
- const command_pattern = /^\s*(\w+)\s+(.*)$/;
31291
- const command_match = text_before_cursor.match(command_pattern);
31405
+ const command_match = text_before_cursor.match(/^\s*(\w+)/);
31292
31406
  if (command_match) {
31293
31407
  const command = command_match[1];
31294
- const path_part = command_match[2];
31408
+ const remainder = text_before_cursor.slice(command_match[0].length);
31409
+ const separator_match = remainder.match(/^\s+/);
31410
+ if (!separator_match) {
31411
+ return null;
31412
+ }
31413
+ const path_part = remainder.slice(separator_match[0].length);
31295
31414
  if (isFileCommand(command)) {
31296
31415
  return {
31297
31416
  type: "command_path",
@@ -33298,6 +33417,7 @@ function create_range_formatting_handler(deps) {
33298
33417
  }
33299
33418
  function create_shutdown_handler(deps, disposables) {
33300
33419
  return async () => {
33420
+ deps?.diagnostics_provider?.on_shutdown();
33301
33421
  deps?.workspace_indexer?.cancel();
33302
33422
  if (disposables?.pending_revalidations) {
33303
33423
  for (const my_token of disposables.pending_revalidations.values()) {
@@ -41519,6 +41639,64 @@ var init_file_rename_handler = __esm(() => {
41519
41639
  init_esm();
41520
41640
  });
41521
41641
 
41642
+ // src/diagnostic-resources.ts
41643
+ function as_record(value) {
41644
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
41645
+ }
41646
+ function parse_diagnostic_uri_set(value) {
41647
+ if (!Array.isArray(value)) {
41648
+ return;
41649
+ }
41650
+ const uris = new Set;
41651
+ for (const candidate of value) {
41652
+ if (typeof candidate !== "string") {
41653
+ continue;
41654
+ }
41655
+ try {
41656
+ const parsed = URI.parse(candidate, true);
41657
+ if (parsed.scheme !== "") {
41658
+ uris.add(parsed.toString());
41659
+ }
41660
+ } catch {}
41661
+ }
41662
+ return uris;
41663
+ }
41664
+ function diagnostic_uris_from_initialization_options(options) {
41665
+ return parse_diagnostic_uri_set(as_record(options)?.["diagnosticUris"]);
41666
+ }
41667
+ function diagnostic_uris_from_notification(params) {
41668
+ return parse_diagnostic_uri_set(as_record(params)?.["diagnosticUris"]);
41669
+ }
41670
+ function same_diagnostic_uri_set(current, next) {
41671
+ if (current === undefined || current.size !== next.size) {
41672
+ return false;
41673
+ }
41674
+ for (const uri of current) {
41675
+ if (!next.has(uri)) {
41676
+ return false;
41677
+ }
41678
+ }
41679
+ return true;
41680
+ }
41681
+ function diagnostic_uri_set_changes(current, next) {
41682
+ const removed = [...current].filter((uri) => !next.has(uri));
41683
+ const added = [...next].filter((uri) => !current.has(uri));
41684
+ return { added, removed };
41685
+ }
41686
+ function settings_initialization_options(options) {
41687
+ const record = as_record(options);
41688
+ if (!record || !("diagnosticUris" in record) || "sight" in record) {
41689
+ return options;
41690
+ }
41691
+ const settings = { ...record };
41692
+ delete settings["diagnosticUris"];
41693
+ return settings;
41694
+ }
41695
+ var DIAGNOSTIC_RESOURCES_CHANGED_NOTIFICATION = "sight/diagnosticResourcesChanged";
41696
+ var init_diagnostic_resources = __esm(() => {
41697
+ init_esm();
41698
+ });
41699
+
41522
41700
  // src/command-database/caches/v18.json
41523
41701
  var v18_default;
41524
41702
  var init_v18 = __esm(() => {
@@ -72242,11 +72420,48 @@ async function create_server(options) {
72242
72420
  let last_applied_indexing_signature = "";
72243
72421
  let config_change_seq = 0;
72244
72422
  let init_options_config = undefined;
72423
+ let editor_diagnostic_uris = undefined;
72424
+ let shutdown_requested = false;
72245
72425
  let last_client_settings = undefined;
72246
72426
  let init_root_uri = null;
72247
72427
  const log_config_warning = (message) => {
72248
72428
  connection.console.log(`Configuration warning: ${message}`);
72249
72429
  };
72430
+ function diagnostics_publish_allowed(uri) {
72431
+ return editor_diagnostic_uris?.has(uri) ?? true;
72432
+ }
72433
+ function update_editor_diagnostic_uris(next) {
72434
+ if (same_diagnostic_uri_set(editor_diagnostic_uris, next)) {
72435
+ return;
72436
+ }
72437
+ const previous = editor_diagnostic_uris;
72438
+ editor_diagnostic_uris = next;
72439
+ if (!diagnostics_provider) {
72440
+ return;
72441
+ }
72442
+ if (previous === undefined) {
72443
+ for (const document of documents.all()) {
72444
+ if (!next.has(document.uri)) {
72445
+ diagnostics_provider.on_document_hidden(document.uri);
72446
+ }
72447
+ }
72448
+ return;
72449
+ }
72450
+ const changes = diagnostic_uri_set_changes(previous, next);
72451
+ for (const uri of changes.removed) {
72452
+ const document = documents.get(uri);
72453
+ if (document) {
72454
+ diagnostics_provider.on_document_hidden(document.uri);
72455
+ }
72456
+ }
72457
+ for (const uri of changes.added) {
72458
+ const document = documents.get(uri);
72459
+ if (document) {
72460
+ diagnostics_provider.on_document_opened(document.uri, document.version);
72461
+ validate_text_document(document);
72462
+ }
72463
+ }
72464
+ }
72250
72465
  function log_project_config_warnings(loaded) {
72251
72466
  for (const my_warning of loaded.warnings) {
72252
72467
  connection.console.log(`Project config warning: ${my_warning.message}`);
@@ -72658,15 +72873,35 @@ async function create_server(options) {
72658
72873
  const snapshot_uri = text_document.uri;
72659
72874
  const snapshot_version = text_document.version;
72660
72875
  const snapshot_content = text_document.getText();
72876
+ const diagnostics_trigger = diagnostics_provider?.trigger_for_validation(snapshot_uri, snapshot_version);
72877
+ const snapshot_is_current = () => documents.get(snapshot_uri) === text_document && text_document.version === snapshot_version;
72878
+ const validation_work_is_current = () => {
72879
+ if (shutdown_requested || !snapshot_is_current()) {
72880
+ return false;
72881
+ }
72882
+ if (!diagnostics_provider) {
72883
+ return true;
72884
+ }
72885
+ if (!diagnostics_publish_allowed(snapshot_uri)) {
72886
+ return true;
72887
+ }
72888
+ return diagnostics_trigger !== undefined && diagnostics_provider.is_validation_current(snapshot_uri, diagnostics_trigger);
72889
+ };
72661
72890
  debounce_manager.schedule_validation(snapshot_uri, snapshot_version, async () => {
72662
72891
  const settings = await get_document_settings(snapshot_uri);
72892
+ if (!validation_work_is_current()) {
72893
+ return;
72894
+ }
72663
72895
  const is_debug = settings.debug === true;
72664
72896
  const my_scope_resolver_config = scope_resolver_config_for(settings);
72665
72897
  const workspace_symbols = workspace_indexer ? workspace_indexer.get_all_symbols() : undefined;
72666
72898
  if (document_store.get(snapshot_uri)) {
72667
- await document_store.update(snapshot_uri, [{ text: snapshot_content }], snapshot_version, workspace_symbols, my_scope_resolver_config);
72899
+ await document_store.update(snapshot_uri, [{ text: snapshot_content }], snapshot_version, workspace_symbols, my_scope_resolver_config, validation_work_is_current);
72668
72900
  } else {
72669
- await document_store.open(snapshot_uri, snapshot_content, snapshot_version, workspace_symbols, my_scope_resolver_config);
72901
+ await document_store.open(snapshot_uri, snapshot_content, snapshot_version, workspace_symbols, my_scope_resolver_config, validation_work_is_current);
72902
+ }
72903
+ if (!validation_work_is_current()) {
72904
+ return;
72670
72905
  }
72671
72906
  if (scope_resolver) {
72672
72907
  const document_state2 = document_store.get(snapshot_uri);
@@ -72725,14 +72960,20 @@ ${scope_resolver.get_reverse_deps_debug_info()}`);
72725
72960
  }
72726
72961
  }
72727
72962
  }
72963
+ if (!snapshot_is_current() || !diagnostics_publish_allowed(snapshot_uri)) {
72964
+ return;
72965
+ }
72728
72966
  const document_state = document_store.get(snapshot_uri);
72729
72967
  if (!document_state) {
72730
72968
  connection.sendDiagnostics({ uri: snapshot_uri, diagnostics: [] });
72731
72969
  return;
72732
72970
  }
72733
72971
  if (diagnostics_provider) {
72972
+ if (!diagnostics_trigger) {
72973
+ return;
72974
+ }
72734
72975
  const diag_workspace_symbols = workspace_indexer ? workspace_indexer.get_all_symbols() : undefined;
72735
- const result = await diagnostics_provider.publish_diagnostics(document_state, settings, diag_workspace_symbols, scope_resolver || undefined, undefined);
72976
+ const result = await diagnostics_provider.publish_diagnostics(document_state, settings, diagnostics_trigger, diag_workspace_symbols, scope_resolver || undefined, undefined);
72736
72977
  if (result.pending) {
72737
72978
  if (is_debug) {
72738
72979
  connection.console.log(`Diagnostics pending for ${snapshot_uri}`);
@@ -72753,7 +72994,8 @@ ${scope_resolver.get_reverse_deps_debug_info()}`);
72753
72994
  connection.onInitialize(create_initialize_handler((caps) => {
72754
72995
  server_capabilities = caps;
72755
72996
  }, (options2) => {
72756
- init_options_config = options2;
72997
+ editor_diagnostic_uris = diagnostic_uris_from_initialization_options(options2);
72998
+ init_options_config = settings_initialization_options(options2);
72757
72999
  }, (root_uri) => {
72758
73000
  init_root_uri = root_uri;
72759
73001
  }));
@@ -72910,6 +73152,9 @@ ${scope_resolver.get_reverse_deps_debug_info()}`);
72910
73152
  }
72911
73153
  });
72912
73154
  documents.onDidOpen((e) => {
73155
+ if (diagnostics_publish_allowed(e.document.uri)) {
73156
+ diagnostics_provider?.on_document_opened(e.document.uri, e.document.version);
73157
+ }
72913
73158
  validate_text_document(e.document);
72914
73159
  });
72915
73160
  documents.onDidClose((e) => {
@@ -72977,6 +73222,12 @@ ${scope_resolver.get_reverse_deps_debug_info()}`);
72977
73222
  }, async () => {
72978
73223
  await reload_project_config_from_active_root();
72979
73224
  }));
73225
+ connection.onNotification(DIAGNOSTIC_RESOURCES_CHANGED_NOTIFICATION, (params) => {
73226
+ const next = diagnostic_uris_from_notification(params);
73227
+ if (next !== undefined) {
73228
+ update_editor_diagnostic_uris(next);
73229
+ }
73230
+ });
72980
73231
  const completion_handler = create_completion_handler(handler_deps);
72981
73232
  const hover_handler = create_hover_handler(handler_deps);
72982
73233
  const definition_handler = create_definition_handler(handler_deps);
@@ -73003,7 +73254,10 @@ ${scope_resolver.get_reverse_deps_debug_info()}`);
73003
73254
  connection.onExecuteCommand((params) => {
73004
73255
  return execute_command_handler(params.command, params.arguments || []);
73005
73256
  });
73006
- connection.onShutdown(shutdown_handler);
73257
+ connection.onShutdown(() => {
73258
+ shutdown_requested = true;
73259
+ return shutdown_handler();
73260
+ });
73007
73261
  connection.onExit(create_exit_handler());
73008
73262
  connection.onRequest("sight/getWorkingDirectory", working_directory_handler);
73009
73263
  const shared_ihlp = create_shared_ihlp_resolver(handler_deps);
@@ -73040,6 +73294,7 @@ var init_server_factory = __esm(() => {
73040
73294
  init_dependency_graph();
73041
73295
  init_esm();
73042
73296
  init_stata_install_paths();
73297
+ init_diagnostic_resources();
73043
73298
  init_v18();
73044
73299
  init_server_handlers();
73045
73300
  import_node8 = __toESM(require_main4(), 1);
@@ -73234,4 +73489,4 @@ export {
73234
73489
  is_cli_entry_point
73235
73490
  };
73236
73491
 
73237
- //# debugId=DFA4590C23722F1564756E2164756E21
73492
+ //# debugId=B7C3CCA891DAB36764756E2164756E21
@@ -1 +1 @@
1
- 8765da4c18f5a23b7c4bfb2890164f0011fa1a4caf26a450fa23ce1b1b28b740 sight-server.js
1
+ 485a12b31b0af8576f9d9b0abe4d3ee35d6ce7a01780df284071c47cc3f08565 sight-server.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbearak/sight",
3
- "version": "0.13.0",
3
+ "version": "0.14.1",
4
4
  "type": "module",
5
5
  "workspaces": [
6
6
  "client"