Module Cobol_lsp.Workspace_symbols

Symbols of documents, for answering workspace/symbol requests.

Symbols of a document are a flat table that holds no closure, cached apart from the (much larger) analysis they are computed from, so that those of documents that are not open can be retrieved without restoring their analysis.

Symbol tables

type symbol = {
  1. name : string;
    (*

    as written in the source

    *)
  2. key : string;
    (*

    name in upper case, with '_' mapped to '-'

    *)
  3. kind : Lsp.Types.SymbolKind.t;
  4. container : string option;
    (*

    name of the enclosing unit or section

    *)
  5. range : Lsp.Types.Range.t;
}
type t = symbol array

Symbols of one document.

val of_ptree : filename:string -> Cobol_ptree.compilation_group -> t

of_ptree ~filename ptree collects the symbols of the document filename: programs, functions, classes, interfaces, methods, sections, paragraphs, and named data items (including constants, condition names and renames). Symbols that stem from copybooks are located at the COPY directive that brings them in.

Caching

slot keys is the slot in which the symbols of the document keys are recorded. It is distinct from every other slot of the document, as symbols are stored at times of their own.

val store : Superbol_cache.Cache.t -> keys:Superbol_project.Analysis.keys -> label:string -> t -> unit

store cache ~keys ~label symbols records symbols in cache, for as long as the analysis for the LSP under Analysis.key_for_lsp keys holds, and supersedes the symbols of previous versions of the document.

val lookup : Superbol_cache.Cache.t -> keys:Superbol_project.Analysis.keys -> resolve:(Superbol_cache.Types.witness -> bool) -> t option

lookup cache ~keys ~resolve retrieves the symbols of the document keys are for from cache.

mem cache ~keys indicates whether cache holds symbols for the document keys, without checking any of their witnesses.

val store_for_analysis : Superbol_cache.Cache.t -> keys:Superbol_project.Analysis.keys -> filename:string -> label:string -> ?fresh:bool -> Superbol_project.Analysis.for_lsp -> unit

store_for_analysis cache ~keys ~filename ~label ?fresh analysis stores the symbols of analysis (for the document filename) in cache unless analysis is that of a copybook, holds no typechecking outputs, or the cache already holds symbols for the document. fresh (defaults to false) indicates analysis was just computed, in which case the cache is not checked first.

Searching

val score : query:string -> symbol -> int option

score ~query symbol is Some s whenever query matches symbol.key, where s is higher for better matches, and None otherwise. query must be normalized with normalize_query.

Every character of the query must appear in the symbol's name, in order (case being ignored, and '_' matching '-'); matches at the beginning of the name or of one of its hyphen-separated words, and consecutive matches, weigh more. The empty query matches everything.

val normalize_query : string -> string

normalize_query q maps q to the form score expects.

search ~query ~limit docs gives the (at most limit) symbols of docs that best match query, from the best to the worst match.