Class: MilkTea::LSP::Workspace
- Inherits:
-
Object
- Object
- MilkTea::LSP::Workspace
- Includes:
- WorkspaceAnalysis, WorkspaceCaches, WorkspaceCollection, WorkspaceDefinitionIndex, WorkspaceDependencyGraph, WorkspaceModuleIndex, WorkspaceStore, WorkspaceUtilities
- Defined in:
- lib/milk_tea/lsp/workspace.rb,
lib/milk_tea/lsp/workspace/store.rb,
lib/milk_tea/lsp/workspace/caches.rb,
lib/milk_tea/lsp/workspace/analysis.rb,
lib/milk_tea/lsp/workspace/utilities.rb,
lib/milk_tea/lsp/workspace/collection.rb,
lib/milk_tea/lsp/workspace/module_index.rb,
lib/milk_tea/lsp/workspace/definition_index.rb,
lib/milk_tea/lsp/workspace/dependency_graph.rb
Overview
Manages open documents, AST cache, token cache, semantic facts cache, and symbol index. Supports incremental document edits and workspace-wide indexing.
Defined Under Namespace
Modules: WorkspaceAnalysis, WorkspaceCaches, WorkspaceCollection, WorkspaceDefinitionIndex, WorkspaceDependencyGraph, WorkspaceModuleIndex, WorkspaceStore, WorkspaceUtilities
Constant Summary collapse
- DOCUMENT_SOURCES =
%w[active-editor visible-editor background-document].freeze
- PERF_LOG_THRESHOLD_MS =
1000- IN_FLIGHT_FACTS_WAIT_MS =
How long a request thread waits (when no facts are available yet) for an in-flight background analysis to finish before falling back to lexical/ nil results. Bounds the main-loop stall while usually returning fresh facts; request threads never run the analysis themselves in this window.
Integer(ENV.fetch('MILK_TEA_LSP_FACTS_WAIT_MS', '500'))
- DEFINITION_KEYWORDS =
Token types that introduce a named definition, in order of precedence.
NOTE: this list is intentionally minimal. Multi-keyword prefixes such as 'const function', 'async function', 'external function', 'foreign function', and visibility modifiers ('public') are captured by the adjacent-token scan in extract_symbols_from_tokens because the scan relies on every pair of adjacent tokens, and the inner keyword (e.g. :function) is always followed by the identifier. If the lexer ever merges a compound keyword into a single token type (e.g. :const_function), it must be added here.
%i[function struct union enum flags variant type const var let extending opaque interface event].freeze
- DOC_COMMENT_PREFIX =
'##'- DOC_TAG_PATTERN =
/\A\s*@([A-Za-z_][A-Za-z0-9_-]*)(?:\s+(.*))?\z/- DEFINITION_LINE_PREFIX =
/^(?:\s)*(?:(?:public|foreign|external)\s+)*(?:function|struct|union|enum|flags|variant|type|const|var|let|extending|opaque|interface|event)\s+/m- DEFINITION_NAME_REGEX =
/^\s*(?:(?:public|foreign|external)\s+)*(?:function|struct|union|enum|flags|variant|type|const|var|let|extending|opaque|interface|event)\s+([A-Za-z_][A-Za-z0-9_]*)\b/
Instance Method Summary collapse
- #cross_file_diagnostics ⇒ Object
-
#initialize ⇒ Workspace
constructor
A new instance of Workspace.
- #reset ⇒ Object
Methods included from WorkspaceUtilities
#dependency_resolution_mode, #dependency_resolution_mode=, #find_call_context, #find_definition_token, #find_dot_receiver, #find_dot_receiver_path, #find_token_at, #platform_override, #platform_override=, #shared_module_cache, #strict_current_root_diagnostics_enabled, #strict_current_root_diagnostics_enabled=, #token_contains_position?, #workspace_root_path, #workspace_root_path=
Methods included from WorkspaceModuleIndex
#apply_module_index_events, #ensure_module_index, #module_importable_names, #module_index_roots, #refresh_module_index_for_workspace, #reset_module_index
Methods included from WorkspaceCollection
Methods included from WorkspaceDefinitionIndex
Methods included from WorkspaceDependencyGraph
#apply_watched_file_change, #clear_dependency_index, #clear_shared_module_cache, #delete_dependency_index, #dependency_index_imports_for, #dependent_open_document_uris_for, #ensure_full_reverse_import_index, #infer_module_name_for_uri, #module_roots_for_path, #normalize_workspace_root_path, #open_document_uris, #refresh_import_dependent_caches, #refresh_open_document_dependency_caches, #related_open_document_uris, #reverse_import_dependents_for, #update_dependency_index, #workspace_root_applicable_for?
Methods included from WorkspaceAnalysis
#analyze_document, #ast_for_content, #compute_facts_for_content, #effective_platform_for_path, #elapsed_ms, #ensure_root_platform_compatible!, #lex_document, #log_perf_breakdown, #monotonic_time, #package_graph_for_path, #parse_document, #perf_breakdown_logging?, #perf_logging?, #perf_verbose?, #warm_document_facts, #with_inferred_module_name
Methods included from WorkspaceCaches
#all_documents, #doc_comment_data_for_definition, #doc_comment_for_definition, #find_all_references, #find_all_references_in, #get_ast, #get_content, #get_facts, #get_symbols, #get_tokens, #get_tooling_snapshot, #index_identifier_tokens, #module_name_for_uri, #peek_facts, #position_to_offset, #remove_identifier_index_entries
Methods included from WorkspaceStore
#apply_incremental_change_to_content, #apply_incremental_changes, #apply_incremental_changes_against_snapshot, #background_document?, #close_document, #document_source, #index_workspace, #open_document, #rename_indexed_file, #set_document_source, #shutdown
Constructor Details
#initialize ⇒ Workspace
Returns a new instance of Workspace.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/milk_tea/lsp/workspace.rb', line 46 def initialize @workspace_root_path = nil @dependency_resolution_mode = :auto @platform_override = nil @strict_current_root_diagnostics_enabled = false @open_documents = {} # uri -> content String from didOpen/didChange @indexed_documents = {} # uri -> content String loaded from disk index @document_sources = {} # uri -> source string from the editor client @document_state_mutex = Mutex.new @tokens_cache = {} # uri -> [Token] @last_good_tokens_cache = {} # uri -> last known-good [Token] @ast_cache = {} # uri -> AST::SourceFile (nil on parse failure) @facts_cache = {} # uri -> SemanticAnalyzer::Facts (projection of cached tooling snapshot facts) @tooling_snapshot_cache = {} # uri -> SemanticAnalyzer::ToolingSnapshot (facts may be nil on structural failure) @symbols_cache = {} # uri -> [{name, kind, line, column}] @doc_comments_cache = {} # uri -> {"line:column" => structured_doc_comment_hash} @last_good_facts_cache = {} # uri -> last SemanticAnalyzer::Facts that succeeded @last_good_tooling_snapshot_cache = {} # uri -> last SemanticAnalyzer::ToolingSnapshot with facts that succeeded @document_module_names = {} # uri -> module name string (populated from last-good facts) @shared_module_cache = {} @facts_cache_mutex = Mutex.new @facts_generation = Hash.new(0) @facts_state_mutex = Mutex.new # Diagnostics cache: uri -> { content_hash:, diagnostics: } @diagnostics_cache = {} @dependency_module_name_by_uri = {} @dependency_imports_by_uri = {} @reverse_import_dependents = Hash.new { |hash, key| hash[key] = Set.new } @full_reverse_index_built = false @full_reverse_index_built = false # Definition index: name -> { uri:, token: } — built lazily from symbols cache. # Caches known matching definitions without forcing a full-workspace index # build on the first global lookup. @definition_index = {} # name -> [{ uri:, token: Token }] @definition_miss_cache = Set.new @definition_candidate_uris = Hash.new { |hash, key| hash[key] = Set.new } @definition_names_by_uri = {} @definition_cache_mutex = Mutex.new @definition_warmup_queue = Queue.new @definition_warmup_enqueued = Set.new @definition_warmup_thread = nil # Identifier index: name -> [{uri:, line:, col:}] — lazily populated from tokens @identifier_index = {} @identifier_index_mutex = Mutex.new @indexed_uris = Set.new # Module index: root path -> { mt_files: {dir => {name => path}}, mt_dirs: {dir => Set<subdir>} } @module_index = {} @module_index_mutex = Mutex.new @indexed_workspace_paths = nil end |
Instance Method Details
#cross_file_diagnostics ⇒ Object
103 104 105 |
# File 'lib/milk_tea/lsp/workspace/collection.rb', line 103 def cross_file_diagnostics @facts_cache_mutex.synchronize { @cross_file_diagnostics } end |
#reset ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/milk_tea/lsp/workspace.rb', line 97 def reset @workspace_root_path = nil @dependency_resolution_mode = :auto @platform_override = nil @strict_current_root_diagnostics_enabled = false @indexed_documents.clear @tokens_cache.clear @last_good_tokens_cache.clear @ast_cache.clear @facts_cache.clear @tooling_snapshot_cache.clear @symbols_cache.clear @doc_comments_cache.clear @last_good_facts_cache.clear @last_good_tooling_snapshot_cache.clear @document_module_names.clear @shared_module_cache.clear @definition_index.clear @identifier_index.clear @full_reverse_index_built = false @indexed_uris.clear @definition_miss_cache.clear @definition_candidate_uris.clear @definition_names_by_uri.clear @definition_warmup_enqueued.clear @dependency_module_name_by_uri.clear @dependency_imports_by_uri.clear @reverse_import_dependents.clear @diagnostics_cache.clear @facts_generation.clear @module_index_mutex.synchronize { @module_index.clear } @indexed_workspace_paths = nil end |