Workspace Class

Definition

A workspace provides access to a active set of source code projects and documents and their associated syntax trees, compilations and semantic models. A workspace has a current solution that is an immutable snapshot of the projects and documents. This property may change over time as the workspace is updated either from live interactions in the environment or via call to the workspace's TryApplyChanges(Solution) method.

public ref class Workspace abstract : IDisposable
public abstract class Workspace : IDisposable
type Workspace = class
    interface IDisposable
Public MustInherit Class Workspace
Implements IDisposable
Inheritance
Workspace
Derived
Implements

Constructors

Workspace(HostServices, String)

Constructs a new workspace instance.

Properties

CanOpenDocuments

True if this workspace supports manually opening and closing documents.

CurrentSolution

The current solution.

The solution is an immutable model of the current set of projects and source documents. It provides access to source text, syntax trees and semantics.

This property may change as the workspace reacts to changes in the environment or after TryApplyChanges(Solution) is called.

Kind

The kind of the workspace. This is generally Host if originating from the host environment, but may be any other name used for a specific kind of workspace.

Options
Obsolete.

Gets or sets the set of all global options and Options. Setter also force updates the CurrentSolution to have the updated Options.

PartialSemanticsEnabled

Override this property if the workspace supports partial semantics for documents.

Services

Services provider by the host for implementing workspace features.

Methods

AdjustReloadedProject(Project, Project)
AdjustReloadedSolution(Solution, Solution)

This method is called during OnSolutionReload. Override this method if you want to manipulate the reloaded solution.

ApplyAdditionalDocumentAdded(DocumentInfo, SourceText)

This method is called during TryApplyChanges(Solution) to add a new additional document to a project.

Override this method to implement the capability of adding additional documents.

ApplyAdditionalDocumentRemoved(DocumentId)

This method is called during TryApplyChanges(Solution) to remove an additional document from a project.

Override this method to implement the capability of removing additional documents.

ApplyAdditionalDocumentTextChanged(DocumentId, SourceText)

This method is called to change the text of an additional document.

Override this method to implement the capability of changing additional document text.

ApplyAnalyzerConfigDocumentAdded(DocumentInfo, SourceText)

This method is called during TryApplyChanges(Solution) to add a new analyzer config document to a project.

Override this method to implement the capability of adding analyzer config documents.

ApplyAnalyzerConfigDocumentRemoved(DocumentId)

This method is called during TryApplyChanges(Solution) to remove an analyzer config document from a project.

Override this method to implement the capability of removing analyzer config documents.

ApplyAnalyzerConfigDocumentTextChanged(DocumentId, SourceText)

This method is called to change the text of an analyzer config document.

Override this method to implement the capability of changing analyzer config document text.

ApplyAnalyzerReferenceAdded(ProjectId, AnalyzerReference)

This method is called during TryApplyChanges(Solution) to add an analyzer reference to a project.

Override this method to implement the capability of adding analyzer references.

ApplyAnalyzerReferenceRemoved(ProjectId, AnalyzerReference)

This method is called during TryApplyChanges(Solution) to remove an analyzer reference from a project.

Override this method to implement the capability of removing analyzer references.

ApplyCompilationOptionsChanged(ProjectId, CompilationOptions)

This method is called during TryApplyChanges(Solution) to change the compilation options.

Override this method to implement the capability of changing compilation options.

ApplyDocumentAdded(DocumentInfo, SourceText)

This method is called during TryApplyChanges(Solution) to add a new document to a project.

Override this method to implement the capability of adding documents.

ApplyDocumentInfoChanged(DocumentId, DocumentInfo)

This method is called to change the info of a document.

Override this method to implement the capability of changing a document's info.

ApplyDocumentRemoved(DocumentId)

This method is called during TryApplyChanges(Solution) to remove a document from a project.

Override this method to implement the capability of removing documents.

ApplyDocumentTextChanged(DocumentId, SourceText)

This method is called to change the text of a document.

Override this method to implement the capability of changing document text.

ApplyMetadataReferenceAdded(ProjectId, MetadataReference)

This method is called during TryApplyChanges(Solution) to add a metadata reference to a project.

Override this method to implement the capability of adding metadata references.

ApplyMetadataReferenceRemoved(ProjectId, MetadataReference)

This method is called during TryApplyChanges(Solution) to remove a metadata reference from a project.

Override this method to implement the capability of removing metadata references.

ApplyParseOptionsChanged(ProjectId, ParseOptions)

This method is called during TryApplyChanges(Solution) to change the parse options.

Override this method to implement the capability of changing parse options.

ApplyProjectAdded(ProjectInfo)

This method is called during TryApplyChanges(Solution) to add a project to the current solution.

Override this method to implement the capability of adding projects.

ApplyProjectChanges(ProjectChanges)

This method is called during TryApplyChanges(Solution) for each project that has been added, removed or changed.

Override this method if you want to modify how project changes are applied.

ApplyProjectReferenceAdded(ProjectId, ProjectReference)

This method is called during TryApplyChanges(Solution) to add a project reference to a project.

Override this method to implement the capability of adding project references.

ApplyProjectReferenceRemoved(ProjectId, ProjectReference)

This method is called during TryApplyChanges(Solution) to remove a project reference from a project.

Override this method to implement the capability of removing project references.

ApplyProjectRemoved(ProjectId)

This method is called during TryApplyChanges(Solution) to remove a project from the current solution.

Override this method to implement the capability of removing projects.

CanApplyChange(ApplyChangesKind)

Determines if the specific kind of change is supported by the TryApplyChanges(Solution) method.

CanApplyCompilationOptionChange(CompilationOptions, CompilationOptions, Project)

Called during a call to TryApplyChanges(Solution) to determine if a specific change to CompilationOptions is allowed.

CanApplyParseOptionChange(ParseOptions, ParseOptions, Project)

Called during a call to TryApplyChanges(Solution) to determine if a specific change to ParseOptions is allowed.

CheckAdditionalDocumentIsInCurrentSolution(DocumentId)

Throws an exception if an additional document is not part of the current solution.

CheckAdditionalDocumentIsNotInCurrentSolution(DocumentId)

Throws an exception if an additional document is already part of the current solution.

CheckAnalyzerConfigDocumentIsInCurrentSolution(DocumentId)

Throws an exception if an analyzer config is not part of the current solution.

CheckAnalyzerConfigDocumentIsNotInCurrentSolution(DocumentId)

Throws an exception if the analyzer config document is already part of the current solution.

CheckCanOpenDocuments()
CheckDocumentCanBeRemoved(DocumentId)
CheckDocumentIsClosed(DocumentId)
CheckDocumentIsInCurrentSolution(DocumentId)

Throws an exception if a document is not part of the current solution.

CheckDocumentIsNotInCurrentSolution(DocumentId)

Throws an exception if a document is already part of the current solution.

CheckDocumentIsOpen(DocumentId)
CheckProjectCanBeRemoved(ProjectId)

Currently projects can always be removed, but this method still exists because it's protected and we don't want to break people who may have derived from Workspace and either called it, or overridden it.

CheckProjectDoesNotContainOpenDocuments(ProjectId)
CheckProjectDoesNotHaveAnalyzerReference(ProjectId, AnalyzerReference)

Throws an exception if a project already has a specific analyzer reference.

CheckProjectDoesNotHaveMetadataReference(ProjectId, MetadataReference)

Throws an exception if a project already has a specific metadata reference.

CheckProjectDoesNotHaveProjectReference(ProjectId, ProjectReference)

Throws an exception if a project already has a specific project reference.

CheckProjectDoesNotHaveTransitiveProjectReference(ProjectId, ProjectId)

Throws an exception if project has a transitive reference to another project.

CheckProjectHasAnalyzerReference(ProjectId, AnalyzerReference)

Throws an exception if a project does not have a specific analyzer reference.

CheckProjectHasMetadataReference(ProjectId, MetadataReference)

Throws an exception if a project does not have a specific metadata reference.

CheckProjectHasProjectReference(ProjectId, ProjectReference)

Throws an exception if a project does not have a specific project reference.

CheckProjectIsInCurrentSolution(ProjectId)

Throws an exception if the project is not part of the current solution.

CheckProjectIsNotInCurrentSolution(ProjectId)

Throws an exception is the project is part of the current solution.

CheckSolutionIsEmpty()

Throws an exception is the solution is not empty.

ClearDocumentData(DocumentId)

This method is called to clear an individual document is removed.

Override this method if you want to do additional work when a document is removed. Call the base method at the end of your method.

ClearOpenDocument(DocumentId)
ClearOpenDocument(DocumentId, Boolean)
ClearProjectData(ProjectId)

This method is called when an individual project is removed.

Override this method if you want to do additional work when a project is removed. Call the base method at the end of your method.

ClearSolution()

Clears all solution data and empties the current solution.

ClearSolutionData()

This method is called when a solution is cleared.

Override this method if you want to do additional work when a solution is cleared. Call the base method at the end of your method.

This method is called while a lock is held. Be very careful when overriding as innapropriate work can cause deadlocks.

CloseAdditionalDocument(DocumentId)

Close the specified additional document in the host environment.

CloseAnalyzerConfigDocument(DocumentId)

Close the specified analyzer config document in the host environment.

CloseDocument(DocumentId)

Close the specified document in the host environment.

CreateSolution(SolutionId)

Create a new empty solution instance associated with this workspace.

CreateSolution(SolutionInfo)

Create a new empty solution instance associated with this workspace.

Dispose()

Disposes this workspace. The workspace can longer be used after it is disposed.

Dispose(Boolean)

Call this method when the workspace is disposed.

Override this method to do additional work when the workspace is disposed. Call this method at the end of your method.

GetAdditionalDocumentName(DocumentId)

Gets the name to use for an additional document in an error message.

GetAnalyzerConfigDocumentName(DocumentId)

Gets the name to use for an analyzer document in an error message.

GetDocumentIdInCurrentContext(SourceTextContainer)

Gets the id for the document associated with the given text container in its current context. Documents are normally associated with a text container when the documents are opened.

GetDocumentName(DocumentId)

Gets the name to use for a document in an error message.

GetOpenDocumentIds(ProjectId)

Gets a list of the currently opened documents.

GetProjectName(ProjectId)

Gets the name to use for a project in an error message.

GetRelatedDocumentIds(SourceTextContainer)

Gets the ids for documents in the CurrentSolution snapshot associated with the given container. Documents are normally associated with a text container when the documents are opened.

GetWorkspaceRegistration(SourceTextContainer)

Returns a WorkspaceRegistration for a given text container.

IsDocumentOpen(DocumentId)

Determines if the document is currently open in the host environment.

OnAdditionalDocumentAdded(DocumentInfo)

Call this method when an additional document is added to a project in the host environment.

OnAdditionalDocumentClosed(DocumentId, TextLoader)
OnAdditionalDocumentOpened(DocumentId, SourceTextContainer, Boolean)
OnAdditionalDocumentRemoved(DocumentId)

Call this method when an additional document is removed from a project in the host environment.

OnAdditionalDocumentTextChanged(DocumentId, SourceText, PreservationMode)

Call this method when the text of an additional document is updated in the host environment.

OnAdditionalDocumentTextLoaderChanged(DocumentId, TextLoader)

Call this method when the text of a additional document is changed on disk.

OnAnalyzerConfigDocumentAdded(DocumentInfo)

Call this method when an analyzer config document is added to a project in the host environment.

OnAnalyzerConfigDocumentClosed(DocumentId, TextLoader)
OnAnalyzerConfigDocumentOpened(DocumentId, SourceTextContainer, Boolean)
OnAnalyzerConfigDocumentRemoved(DocumentId)

Call this method when an analyzer config document is removed from a project in the host environment.

OnAnalyzerConfigDocumentTextChanged(DocumentId, SourceText, PreservationMode)

Call this method when the text of an analyzer config document is updated in the host environment.

OnAnalyzerConfigDocumentTextLoaderChanged(DocumentId, TextLoader)

Call this method when the text of a analyzer config document is changed on disk.

OnAnalyzerReferenceAdded(ProjectId, AnalyzerReference)

Call this method when an analyzer reference is added to a project in the host environment.

OnAnalyzerReferenceRemoved(ProjectId, AnalyzerReference)

Call this method when an analyzer reference is removed from a project in the host environment.

OnAssemblyNameChanged(ProjectId, String)

Call this method when a project's assembly name is changed in the host environment.

OnCompilationOptionsChanged(ProjectId, CompilationOptions)

Call this method when a project's compilation options are changed in the host environment.

OnDocumentAdded(DocumentInfo)

Call this method when a document is added to a project in the host environment.

OnDocumentClosed(DocumentId, TextLoader, Boolean)
OnDocumentClosing(DocumentId)

Override this method to act immediately when a document is closing, as opposed to waiting for the corresponding workspace changed event to fire asynchronously.

OnDocumentContextUpdated(DocumentId)

Call this method when a document has been made the active context in the host environment.

OnDocumentInfoChanged(DocumentId, DocumentInfo)

Call this method when the document info changes, such as the name, folders or file path.

OnDocumentOpened(DocumentId, SourceTextContainer, Boolean)
OnDocumentReloaded(DocumentInfo)

Call this method when a document is reloaded in the host environment.

OnDocumentRemoved(DocumentId)

Call this method when a document is removed from a project in the host environment.

OnDocumentsAdded(ImmutableArray<DocumentInfo>)

Call this method when multiple document are added to one or more projects in the host environment.

OnDocumentSourceCodeKindChanged(DocumentId, SourceCodeKind)

Call this method when the SourceCodeKind of a document changes in the host environment.

OnDocumentTextChanged(Document)

Override this method to act immediately when the text of a document has changed, as opposed to waiting for the corresponding workspace changed event to fire asynchronously.

OnDocumentTextChanged(DocumentId, SourceText, PreservationMode)

Call this method when the text of a document is updated in the host environment.

OnDocumentTextLoaderChanged(DocumentId, TextLoader)

Call this method when the text of a document is changed on disk.

OnMetadataReferenceAdded(ProjectId, MetadataReference)

Call this method when a metadata reference is added to a project in the host environment.

OnMetadataReferenceRemoved(ProjectId, MetadataReference)

Call this method when a metadata reference is removed from a project in the host environment.

OnOutputFilePathChanged(ProjectId, String)

Call this method when a project's output file path is changed in the host environment.

OnOutputRefFilePathChanged(ProjectId, String)

Call this method when a project's output ref file path is changed in the host environment.

OnParseOptionsChanged(ProjectId, ParseOptions)

Call this method when a project's parse options are changed in the host environment.

OnProjectAdded(ProjectInfo)

Call this method to respond to a project being added/opened in the host environment.

OnProjectNameChanged(ProjectId, String, String)

Call this method when a project's name is changed in the host environment.

OnProjectReferenceAdded(ProjectId, ProjectReference)

Call this method when a project reference is added to a project in the host environment.

OnProjectReferenceRemoved(ProjectId, ProjectReference)

Call this method when a project reference is removed from a project in the host environment.

OnProjectReloaded(ProjectInfo)

Call this method to respond to a project being reloaded in the host environment.

OnProjectRemoved(ProjectId)

Call this method to respond to a project being removed from the host environment.

OnSolutionAdded(SolutionInfo)

Call this method to respond to a solution being opened in the host environment.

OnSolutionReloaded(SolutionInfo)

Call this method to respond to a solution being reloaded in the host environment.

OnSolutionRemoved()

This method is called when the solution is removed from the workspace.

Override this method if you want to do additional work when the solution is removed. Call the base method at the end of your method. Call this method to respond to a solution being removed/cleared/closed in the host environment.

OnWorkspaceFailed(WorkspaceDiagnostic)
OpenAdditionalDocument(DocumentId, Boolean)

Open the specified additional document in the host environment.

OpenAnalyzerConfigDocument(DocumentId, Boolean)

Open the specified analyzer config document in the host environment.

OpenDocument(DocumentId, Boolean)

Open the specified document in the host environment.

RaiseDocumentActiveContextChangedEventAsync(Document)
RaiseDocumentActiveContextChangedEventAsync(SourceTextContainer, DocumentId, DocumentId)
RaiseDocumentClosedEventAsync(Document)
RaiseDocumentOpenedEventAsync(Document)
RaiseTextDocumentClosedEventAsync(TextDocument)
RaiseTextDocumentOpenedEventAsync(TextDocument)
RaiseWorkspaceChangedEventAsync(WorkspaceChangeKind, Solution, Solution, ProjectId, DocumentId)
RegisterText(SourceTextContainer)

Register a correspondence between a text container and a workspace.

ScheduleTask(Action, String)

Executes an action as a background task, as part of a sequential queue of tasks.

ScheduleTask<T>(Func<T>, String)

Execute a function as a background task, as part of a sequential queue of tasks.

SetCurrentSolution(Solution)

Sets the CurrentSolution of this workspace. This method does not raise a WorkspaceChanged event.

TryApplyChanges(Solution)

Apply changes made to a solution back to the workspace.

The specified solution must be one that originated from this workspace. If it is not, or the workspace has been updated since the solution was obtained from the workspace, then this method returns false. This method will still throw if the solution contains changes that are not supported according to the CanApplyChange(ApplyChangesKind) method.

TryGetWorkspace(SourceTextContainer, Workspace)

Gets the workspace associated with the specific text container.

UnregisterText(SourceTextContainer)

Unregister a correspondence between a text container and a workspace.

UpdateReferencesAfterAdd()

Updates all projects to properly reference other projects as project references instead of metadata references.

Events

DocumentActiveContextChanged

An event that is fired when the active context document associated with a buffer changes.

DocumentClosed

An event that is fired when a Document is closed in the editor.

DocumentOpened

An event that is fired when a Document is opened in the editor.

TextDocumentClosed

An event that is fired when any TextDocument is closed in the editor.

TextDocumentOpened

An event that is fired when any TextDocument is opened in the editor.

WorkspaceChanged

An event raised whenever the current solution is changed.

WorkspaceFailed

An event raised whenever the workspace or part of its solution model fails to access a file or other external resource.

Applies to