Theia API Documentation v1.77.0
    Preparing search index...

    The workspace service.

    Hierarchy (View Summary)

    Implements

    Index
    _ready: Deferred<void> = ...
    _roots: FileStat[] = []
    _workspace: FileStat | undefined
    computedRootNames: Map<string, string> = ...

    The names of the roots read by the last computeRoots, not yet published.

    configuredRootNames: Map<string, string> = ...

    The names of the roots, published together with _roots when onWorkspaceChanged fires.

    configuredRootNamesByUri:
        | { byUri: Map<string, string | undefined>; names: Map<string, string> }
        | undefined

    The configured root names by the string of a root URI as passed to getConfiguredRootName, for the configuredRootNames they were looked up in.

    deferredRoots: Deferred<FileStat[]> = ...
    envVariableServer: EnvVariablesServer
    fileService: FileService
    fsPreferences: FileSystemPreferences
    labelProvider: LabelProvider
    logger: ILogger
    messageService: MessageService
    onWorkspaceChangeEmitter: Emitter<FileStat[]> = ...
    onWorkspaceLocationChangedEmitter: Emitter<FileStat | undefined> = ...
    preferenceImpl: PreferenceService
    rootNamesCache:
        | {
            names: ReadonlyMap<string, URI>;
            namesByRoot: ReadonlyMap<string, string>;
        }
        | undefined

    The root names, and the names by root URI, which depend on each other. Reset whenever the roots change.

    rootWatchers: Map<string, Disposable> = ...
    schemaUpdater: WorkspaceSchemaUpdater
    toDisposeOnWorkspace: DisposableCollection = ...
    untitledWorkspaceService: UntitledWorkspaceService
    windowService: WindowService
    windowTitleService: WindowTitleService
    workspaceFileService: WorkspaceFileService
    workspaceHandlingContribution: ContributionProvider<
        WorkspaceHandlingContribution,
    >
    • Computes the workspace roots. Also sets computedRootNames to the names given to the roots in the workspace file, which updateRoots publishes with the roots, see getConfiguredRootName. An override that does not call super has to set computedRootNames itself, otherwise the names of the previous roots remain.

      Returns Promise<FileStat[]>

    • Return true if one of the paths in paths array is present in the workspace NOTE: You should always explicitly use / as the separator between the path segments.

      Parameters

      • paths: string[]

      Returns Promise<boolean>

    • Returns the name given to the workspace root by the name property of its folder entry in the workspace file. This is the name shown for the root, as WorkspaceFolder.name in VS Code. Unlike the unique names of getRootNames, it is chosen by the user and not used to address files.

      Parameters

      • rootUri: URI

        URI of the workspace root

      Returns string | undefined

      the name of the root, or undefined if the root has no name or is not a workspace root

    • Resolves to the default workspace URI as string.

      The default implementation tries to extract the default workspace location from the window.location.hash, then falls-back to the most recently used workspace root from the server.

      It is not ensured that the resolved workspace URI is valid, it can point to a non-existing location.

      Returns MaybePromise<string | undefined>

    • Returns a unique name for each workspace root, in workspace order.

      A root is named after its directory basename, e.g. backend. Roots that share a basename are treated as peers: each of them is named after the shortest tail of its path that tells them apart, e.g. alice/app and bob/app. A name that another name starts with, e.g. alice next to alice/app, is qualified in the same way, e.g. work/alice, so that every path resolves to the root it came from. The names are thus always the ending of the real path, so they match what appears in terminal output, compiler errors and the like.

      These are the root names used by getRootPrefixedPath and resolved by resolveRootPrefixedPath.

      Returns ReadonlyMap<string, URI>

    • Returns a workspace-relative path prefixed with the containing root's directory name, e.g. backend/src/index.ts.

      In a single-root workspace the root name is still included so that the format is consistent regardless of how many roots are open.

      Falls back to the absolute filesystem path if the URI is not contained in any workspace root.

      Parameters

      • uri: URI

        URI of the file

      Returns string

    • Returns the workspace root uri that the given file belongs to. In case that the file is found in more than one workspace roots, returns the root that is closest to the file. If the file is not from the current workspace, returns undefined.

      Parameters

      • uri: URI | undefined

        URI of the file

      Returns URI | undefined

    • Returns true if the current window is connected to a remote backend. In remote sessions, we must not overwrite the local MRU with the remote workspace's file URI, as the local MRU should retain the remote connection URI (e.g. devcontainer://...) so the session can be restored on restart.

      Detection: the backend port is always in ?port=. When connected to a remote, the URL also has ?localPort= (the original backend port).

      Returns boolean

    • On unload, we set our workspace root as the last recently used on the backend.

      In the browser, we use onStop (fire-and-forget) because onWillStop actions are never executed during browser tab close and returning an OnWillStopAction would trigger an unwanted "Leave site?" confirmation dialog.

      In Electron, we use onWillStop so the workspace is persisted before the window closes.

      Returns void

    • Adds the next parent segment to the name of a root, unless the name is its whole path or its URI already.

      Parameters

      • entry: { name: string; root: URI }

      Returns boolean

      whether the name was qualified

    • Qualifies a root name that another root name starts with, e.g. alice next to alice/app, by more segments of its path, as a path in the one root would otherwise resolve to the other. If the root named alice/app is the app folder of the root named alice, the names are left as they are: the nested root is then also the one that getRootPrefixedPath names its files after.

      Parameters

      • names: Map<string, URI>

      Returns Map<string, URI>

    • Resolves a path in the format of getRootPrefixedPath, i.e. <rootName>/<relativePath> or a bare <rootName>, to a URI. If more than one root name is a prefix of the path, which is the case when a root named a has a subfolder b and another root is named a/b, the longest one wins.

      Parameters

      • rootPrefixedPath: string

      Returns URI | undefined

      undefined if the path is absolute, does not start with a root name or leaves its root.

    • Resolves a path that contains the basename of a workspace root, preceded by nothing or by the trailing segments of the root's parent path, e.g. bob/app/src for the root /home/bob/app. Unlike resolveRootPrefixedPath, this does not depend on the current root names, so it also resolves paths that were prefixed with a root name before the workspace roots changed.

      Parameters

      • supraRelativePath: string

      Returns URI[]

      the distinct candidates in workspace order, which are several if the path is ambiguous, or none if the path is absolute, leaves its root or does not contain the basename of a root.

    • Removes deleteCount roots starting at start and inserts the given roots there, and writes the result to the workspace file. A root to add can be given a name, which is written to the workspace file as the name of its folder entry.

      Parameters

      Returns Promise<URI[]>

      the URIs of the removed roots

    • Splits a /-separated path that starts with a root name, as in getRootPrefixedPath, into that root and the rest of the path, which is empty for a bare root name. The rest is not normalized, so it may as well be a glob. If more than one root name is a prefix of the path, the longest one wins.

      Parameters

      • rootPrefixedPath: string

      Returns { rest: string; rootName: string; rootUri: URI } | undefined

      undefined if the path does not start with a root name.