Module Cobol_lsp.Project

Type definitions

module TYPES : sig ... end
include module type of TYPES with type path = TYPES.path and type rootdir = TYPES.rootdir and type project = TYPES.project and type layout = TYPES.layout
include module type of Superbol_project.Config.TYPES with type path = TYPES.path
type path = TYPES.path =
  1. | RelativeToProjectRoot of string
  2. | RelativeToFileDir of string
type config = {
  1. mutable cobol_config : Cobol_config.t;
  2. mutable dialect_name : string;
    (*

    Builtin GnuCOBOL dialect name, or the name of a configuration file.

    *)
  3. mutable source_format : Cobol_config.source_format_spec;
  4. mutable source_format_by_extension : (string * Cobol_config.source_format_spec) list;
  5. mutable libpath : path list;
  6. mutable libexts : string list;
  7. mutable indent_config : (string * int) list;
  8. mutable exclude_dirs : string list;
    (*

    See excludes_dir.

    *)
  9. mutable mf_comment : bool;
  10. mutable source_encoding : Cobol_common.Text_encoding.t option;
    (*

    Encoding that source files read from disk are decoded with (see Project.decode_source). Not saved in the configuration file: the LSP server sets it according to the settings of its client.

    *)
  11. toml_handle : Ezr_toml.toml_handle;
}
exception ERROR of Superbol_project__.Project_diagnostics.error
include module type of Superbol_project.TYPES with type rootdir = TYPES.rootdir with type project = TYPES.project with type layout = TYPES.layout
type rootdir = TYPES.rootdir
type project = TYPES.project = {
  1. rootdir : rootdir;
  2. config : Superbol_project__.Project_config.TYPES.config;
  3. config_filename : string;
}
type layout = TYPES.layout = {
  1. project_config_filename : string;
    (*

    Name of the TOML file that is to be found at the root of each project's directory tree.

    *)
  2. relative_work_dirname : string option;
    (*

    Relative name of a directory where the LSP should put its working files (caches, etc). No such storage is allowed when None.

    *)
  3. rootdir_fallback_policy : rootdir_fallback_policy;
    (*

    Policy to determine the root directory of projects based on individual filenames.

    *)
}
and rootdir_fallback_policy =
  1. | Same_as_file_directory
  2. | Given_directory of string
type cache_storage_location =
  1. | No_cache_storage
  2. | Store_cache_in_relative_dir of {
    1. relative_dirname : string;
      (*

      Name of cache directory, relative to project root directory.

      *)
    }
  3. | Store_cache_in_shared_dir of {
    1. dirname : string;
    }
type settings_reporter = {
  1. report_dialect_diags : dialect_name:string -> dialect_file:string option -> project -> Cobol_common.Diagnostics.Set.t -> unit;
    (*

    Diagnostics about loading the configuration of dialect dialect_name for a project, from dialect_file if any

    *)
  2. report_config_error : Superbol_project.Diagnostics.error -> unit;
  3. report_invalid_setting : key:string -> string -> unit;
}

How problems met while applying client settings are reported.

type t = project

Constructors & accessors

val for_ : rootdir:rootdir -> layout:layout -> t

for_ ~rootdir ~layout retrieves a project based on its root directory. This may trigger reading project configuration files if the project was not yet loaded.

May puplish notifications about the loading process directly via Lsp_io.send_diagnostics or Lsp_io.send_notification, and send diagnostics about loaded configuration files via Lsp_diagnostics.publish.

val in_existing_dir : string -> layout:layout -> t

in_existing_dir dirname ~layout retrieves a project after checking dirname actually refers to an exising directory that can serve as root for the project.

The same notes as for for_ apply, with the addition that Invalid_argument is raised in case dirname is not the name of an existing directory.

val rootdir_for : uri:Lsp.Uri.t -> layout:layout -> rootdir

rootdir_for ~uri ~layout locates the project directory (that contains a file with given name layout.project_config_filename) for a file at the given URI. The behavior when no such file is found is that of Superbol_project.rootdir_for.

val copybook_lookup_config_for : uri:Lsp.Uri.t -> t -> Cobol_common.Copybook.TYPES.lookup_config

copybook_lookup_config_for ~uri project constructs a copybook lookup configuration for a source file at the given URI, in the given project.

val detect_copybook : uri:Lsp.Uri.t -> ?contents:string -> t -> bool

detect_copybook ~uri ?contents project indicates whether a document at the given URI for project should be treated as a copybook.

Cached representation

type cached
val to_cache : t -> cached

to_cache project constructs a cached representation for project.

val of_cache : rootdir:rootdir -> layout:layout -> cached -> t

of_cache ~rootdir ~layout cached_project attempts to load and return a cached project. Behaves like for_ ~rootdir ~layout in case of error (outdated or missing configuration file).

Collections

module SET : sig ... end
module MAP : Stdlib.Map.S with type key = t

Configuration management

Warning: functions below that return a Boolean actually perform some mutations on project's configurations. They return true if the configuration of the given project has changed.

val reload_project_config : t -> bool
val lsp_settings_reporter : settings_reporter

Reports problems as an LSP server does: on its client.

val update_project_config : ?platform:Cobol_common.Platform.TYPES.platform -> ?reporter:settings_reporter -> (string * Yojson.Safe.t) list -> t -> bool

update_project_config ~platform ~reporter assoc project applies to project the settings of the superbol.cobol section of an LSP client given in assoc, reporting problems with reporter (defaults to lsp_settings_reporter). Returns true if the configuration changed.

Other front-ends may use this to configure projects as the LSP server does, so that they share cached analyses. They must then give their own platform to load dialect files with, as the default (Lsp_platform.record) is only set up once the server runs.

val get_project_config : ?flat:bool -> t -> Yojson.Safe.t

Miscellaneous

val rootdir : t -> rootdir
val rooturi : t -> Lsp.Uri.t
val string_of_rootdir : rootdir -> string
val relative_path_for : uri:Lsp.Uri.t -> t -> string
val absolute_path_for : filename:string -> t -> string