Options
All
  • Public
  • Public/Protected
  • All
Menu

Module workspace

Namespace for dealing with the current workspace. A workspace is the representation of the folder that has been opened. There is no workspace when just a file but not a folder has been opened.

The workspace offers support for listening to fs events and for finding files. Both perform well and run outside the editor-process so that they should be always used instead of nodejs-equivalents.

Index

Variables

Let name

name: string | undefined

The name of the workspace. undefined when no folder has been opened.

readonly

Const onDidChangeConfiguration

onDidChangeConfiguration: Event<ConfigurationChangeEvent>

An event that is emitted when the configuration changed.

Const onDidChangeTextDocument

onDidChangeTextDocument: Event<TextDocumentChangeEvent>

An event that is emitted when a text document is changed. This usually happens when the contents changes but also when other things like the dirty-state changes.

Const onDidChangeWorkspaceFolders

onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>

An event that is emitted when a workspace folder is added or removed.

Const onDidCloseTextDocument

onDidCloseTextDocument: Event<TextDocument>

An event that is emitted when a text document is disposed.

To add an event listener when a visible text document is closed, use the TextEditor events in the window namespace. Note that this event is not emitted when a TextEditor is closed but the document remains open in another visible text editor.

Const onDidOpenTextDocument

onDidOpenTextDocument: Event<TextDocument>

An event that is emitted when a text document is opened.

To add an event listener when a visible text document is opened, use the TextEditor events in the window namespace. Note that:

Const onDidSaveTextDocument

onDidSaveTextDocument: Event<TextDocument>

An event that is emitted when a text document is saved to disk.

Let textDocuments

textDocuments: TextDocument[]

All text documents currently known to the system.

readonly

Let workspaceFolders

workspaceFolders: WorkspaceFolder[] | undefined

List of workspace folders or undefined when no folder is open. Note that the first entry corresponds to the value of rootPath.

readonly

Functions

createFileSystemWatcher

  • createFileSystemWatcher(globPattern: GlobPattern, ignoreCreateEvents?: boolean, ignoreChangeEvents?: boolean, ignoreDeleteEvents?: boolean): FileSystemWatcher

findFiles

  • Find files across all workspace folders in the workspace.

    sample

    findFiles('**​/*.js', '**​/node_modules/**', 10)

    Parameters

    • include: GlobPattern

      A glob pattern that defines the files to search for. The glob pattern will be matched against the file paths of resulting matches relative to their workspace. Use a relative pattern to restrict the search results to a workspace folder.

    • Optional exclude: GlobPattern | undefined

      A glob pattern that defines files and folders to exclude. The glob pattern will be matched against the file paths of resulting matches relative to their workspace. When undefined only default excludes will apply, when null no excludes will apply.

    • Optional maxResults: number

      An upper-bound for the result.

    • Optional token: CancellationToken

      A token that can be used to signal cancellation to the underlying search engine.

    Returns PromiseLike<Uri[]>

    A thenable that resolves to an array of resource identifiers. Will return no results if no workspace folders are opened.

getConfiguration

  • Get a workspace configuration object.

    When a section-identifier is provided only that part of the configuration is returned. Dots in the section-identifier are interpreted as child-access, like { myExt: { setting: { doIt: true }}} and getConfiguration('myExt.setting').get('doIt') === true.

    When a resource is provided, configuration scoped to that resource is returned.

    Parameters

    • Optional section: string

      A dot-separated identifier.

    • Optional resource: Uri | null

      A resource for which the configuration is asked for

    Returns WorkspaceConfiguration

    The full configuration or a subset.

openTextDocument

  • openTextDocument(uri: Uri): Promise<TextDocument | undefined>
  • openTextDocument(fileName: string): Promise<TextDocument | undefined>
  • openTextDocument(options?: object): Promise<TextDocument | undefined>
  • Opens a document. Will return early if this document is already open. Otherwise the document is loaded and the didOpen-event fires.

    The document is denoted by an uri. Depending on the scheme the following rules apply:

    • file-scheme: Open a file on disk, will be rejected if the file does not exist or cannot be loaded.
    • untitled-scheme: A new file that should be saved on disk, e.g. untitled:c:\frodo\new.js. The language will be derived from the file name.
    • For all other schemes the registered text document content providers are consulted.

    Note that the lifecycle of the returned document is owned by the editor and not by the extension. That means an onDidClose-event can occur at any time after opening it.

    Parameters

    • uri: Uri

      Identifies the resource to open.

    Returns Promise<TextDocument | undefined>

    A promise that resolves to a document.

  • A short-hand for openTextDocument(Uri.file(fileName)).

    see

    openTextDocument

    Parameters

    • fileName: string

      A name of a file on disk.

    Returns Promise<TextDocument | undefined>

    A promise that resolves to a document.

  • Opens an untitled text document. The editor will prompt the user for a file path when the document is to be saved. The options parameter allows to specify the language and/or the content of the document.

    Parameters

    • Optional options: object

      Options to control how the document will be created.

      • Optional content?: string
      • Optional language?: string

    Returns Promise<TextDocument | undefined>

    A promise that resolves to a document.

registerFileSystemProvider

  • Register a filesystem provider for a given scheme, e.g. ftp.

    There can only be one provider per scheme and an error is being thrown when a scheme has been claimed by another provider or when it is reserved.

    Parameters

    • scheme: string

      The uri-scheme the provider registers for.

    • provider: FileSystemProvider

      The filesystem provider.

    • Optional options: object

      Immutable metadata about the provider.

      • Optional isCaseSensitive?: boolean
      • Optional isReadonly?: boolean

    Returns Disposable

    A disposable that unregisters this provider when being disposed.

registerTextDocumentContentProvider

  • Register a text document content provider.

    Only one provider can be registered per scheme.

    Parameters

    Returns Disposable

    A disposable that unregisters this provider when being disposed.