Use newer Roslyn APIs in the language service#8499
Conversation
| snapshot.Properties.TryGetValue(ConfigurationGeneral.TargetPathProperty, out string? binOutputPath); | ||
| snapshot.Properties.TryGetValue(ConfigurationGeneral.MSBuildProjectFullPathProperty, out string? projectFilePath); | ||
| snapshot.Properties.TryGetValue(ConfigurationGeneral.AssemblyNameProperty, out string? assemblyName); | ||
| snapshot.Properties.TryGetValue(ConfigurationGeneral.CommandLineArgsForDesignTimeEvaluationProperty, out string? commandLineArgsForDesignTimeEvaluation); | ||
|
|
||
| if (string.IsNullOrEmpty(languageName) || string.IsNullOrEmpty(binOutputPath) || string.IsNullOrEmpty(projectFilePath)) | ||
| if (string.IsNullOrEmpty(languageName) || string.IsNullOrEmpty(projectFilePath)) |
There was a problem hiding this comment.
We no longer pull these properties out on our side. Roslyn will obtain them via an object we provide.
|
|
||
| try | ||
| { | ||
| EvaluationDataAdapter evaluationData = new(snapshot.Properties); |
There was a problem hiding this comment.
This object allows Roslyn to call us back for any property that's in ConfigurationGeneral. In future we may also allow requesting arbitrary project properties.
| _context = await _workspaceProjectContextFactory.Value.CreateProjectContextAsync( | ||
| languageName, | ||
| _contextId, | ||
| projectFilePath, | ||
| _projectGuid, | ||
| _contextId, | ||
| languageName, | ||
| evaluationData, | ||
| hostObject, | ||
| binOutputPath, | ||
| assemblyName, | ||
| cancellationToken); |
There was a problem hiding this comment.
Calling the new overload.
|
|
||
| // Update additional properties within a batch to avoid thread pool starvation. | ||
| // https://github.com/dotnet/project-system/issues/8027 | ||
| _context.StartBatch(); | ||
|
|
||
| try | ||
| { | ||
| _context.LastDesignTimeBuildSucceeded = false; // By default, turn off diagnostics until the first design time build succeeds for this project. | ||
|
|
||
| // Pass along any early approximation we have of the command line options | ||
| #pragma warning disable CS0618 // This was obsoleted in favor of the one that takes an array, but here just the string is easier; we'll un-Obsolete this API | ||
| _context.SetOptions(commandLineArgsForDesignTimeEvaluation ?? ""); | ||
| #pragma warning restore CS0618 // Type or member is obsolete | ||
| } | ||
| finally | ||
| { | ||
| await _context.EndBatchAsync(); | ||
| } |
There was a problem hiding this comment.
This whole post-construction update is no longer needed.
...S/ProjectSystem/VS/PropertyPages/Editors/ImplicitUsingsEditor/CSharpImplicitUsingsControl.cs
Outdated
Show resolved
Hide resolved
| #pragma warning disable CS0618 // Type or member is obsolete | ||
| Renamer.RenameDocumentActionSet documentAction = await Renamer.RenameDocumentAsync(oldDocument, null!, documentFolders); | ||
| #pragma warning restore CS0618 // Type or member is obsolete |
There was a problem hiding this comment.
Roslyn has deprecated a bunch of these rename APIs.
@ocallesp do we have a work item tracking the update of this? If not, could you file one please?
|
I struggled making the package references and versions work here. It builds on my machine, though I half expect it to fail in CI. I'm not convinced the approach here is right, and it seems like some of the packages we need are incorrectly authored or missing from the feeds we source them from. I will revisit this next soon. |
| await _context.EndBatchAsync(); | ||
| } | ||
| } | ||
| catch (Exception ex) |
...Studio.ProjectSystem.Managed.VS/ProjectSystem/VS/PropertyPages/Editors/PropertyEditorBase.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Workspace.cs
Show resolved
Hide resolved
src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Workspace.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/LanguageServices/Workspace.cs
Outdated
Show resolved
Hide resolved
c65ff00 to
4b49a49
Compare
66cb773 to
bd63af1
Compare
9920029 to
b9a7494
Compare
This new API: - allows Roslyn to request additional properties in future, without requiring a corresponding change in the Project System. - avoids having to create a wasteful batched update immediately after constructing the workspace
b9a7494 to
ba901f0
Compare
Historically, the set of project properties we passed to Roslyn when initialising an `IWorkspaceProjectContext` was hard-coded in the project system. We changed this recently in dotnet#8499, and introduced a means for Roslyn to request whatever properties they wanted, allowing Roslyn to make changes without requiring a synchronised change in the project system. With that change, we serviced property value requests using `ProjectRuleSource` data. This limited Roslyn to only those properties present in our `ConfigurationGeneral` XAML rule file. This commit uses a `ProjectInstance` to service such requests instead. This means that Roslyn can add new projects in their own props/targets, and not need the project system to make any changes in order to provide those values. Motivated by a bug exposed through dotnet/roslyn#64749 which added required property `OutputAssemblyForDesignTimeEvaluation` which did not exist in our rules, leading to runtime errors.
Historically, the set of project properties we passed to Roslyn when initialising an `IWorkspaceProjectContext` was hard-coded in the project system. We changed this recently in dotnet#8499, and introduced a means for Roslyn to request whatever properties they wanted, allowing Roslyn to make changes without requiring a synchronised change in the project system. With that change, we serviced property value requests using `ProjectRuleSource` data. This limited Roslyn to only those properties present in our `ConfigurationGeneral` XAML rule file. This commit uses a `ProjectInstance` to service such requests instead. This means that Roslyn can add new projects in their own props/targets, and not need the project system to make any changes in order to provide those values. Motivated by a bug exposed through dotnet/roslyn#64749 which added required property `OutputAssemblyForDesignTimeEvaluation` which did not exist in our rules, leading to runtime errors.
Historically, the set of project properties we passed to Roslyn when initialising an `IWorkspaceProjectContext` was hard-coded in the project system. We changed this recently in dotnet#8499, and introduced a means for Roslyn to request whatever properties they wanted, allowing Roslyn to make changes without requiring a synchronised change in the project system. With that change, we serviced property value requests using `ProjectRuleSource` data. This limited Roslyn to only those properties present in our `ConfigurationGeneral` XAML rule file. This commit uses a `ProjectInstance` to service such requests instead. This means that Roslyn can add new projects in their own props/targets, and not need the project system to make any changes in order to provide those values. Motivated by a bug exposed through dotnet/roslyn#64749 which added required property `OutputAssemblyForDesignTimeEvaluation` which did not exist in our rules, leading to runtime errors.
Historically, the set of project properties we passed to Roslyn when initialising an `IWorkspaceProjectContext` was hard-coded in the project system. We changed this recently in dotnet#8499, and introduced a means for Roslyn to request whatever properties they wanted, allowing Roslyn to make changes without requiring a synchronised change in the project system. With that change, we serviced property value requests using `ProjectRuleSource` data. This limited Roslyn to only those properties present in our `ConfigurationGeneral` XAML rule file. This commit uses a `ProjectInstance` to service such requests instead. This means that Roslyn can add new projects in their own props/targets, and not need the project system to make any changes in order to provide those values. Motivated by a bug exposed through dotnet/roslyn#64749 which added required property `OutputAssemblyForDesignTimeEvaluation` which did not exist in our rules, leading to runtime errors.
@tmat and I designed a new API for the interaction between the .NET Project System and Roslyn when creating instances of
IWorkspaceProjectContext.This new API:
Allows Roslyn to (generally) request additional properties from the project system, without requiring a corresponding change in the project system.
Avoids having to create a wasteful batched update immediately after constructing the workspace.
This PR updates the API we use.
Bumping that package pulled the thread on a whole bunch of other package upgrades, including analyzer changes that lead to
.editorconfigchanges, some naming guideline changes, and some suppressions.Microsoft Reviewers: Open in CodeFlow