Rewrite VS extension using VisualStudio.Extensibility SDK for VS2022/2026 compatibility#720
Rewrite VS extension using VisualStudio.Extensibility SDK for VS2022/2026 compatibility#720
Conversation
Visual Studio does not activate ILanguageClient for base content types like "code". Each specific content type must be explicitly registered for the language client to be activated when files of that type are opened. Added content type registrations for: C/C++, CSharp, F#, JavaScript, TypeScript, HTML, JSON, XML, XAML, Python, Ruby, Perl, PHP, Java, Go, Rust, SQL, Lua, Swift, PowerShell, shellscript, yaml, plaintext. Kept "code" as fallback for any types not explicitly listed. Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
|
@copilot update description and title |
Updated the PR description to reflect the full scope of changes - rewriting the VS extension using the new VisualStudio.Extensibility SDK for VS 2022/2026 compatibility. The title should now be: "Rewrite VS extension using VisualStudio.Extensibility SDK" Note: I can update the PR description but cannot directly modify the PR title. You may need to update the title manually to something like "Rewrite VS extension using VisualStudio.Extensibility SDK for VS2022/2026 compatibility". |
… to include in the key too
…m/microsoft/DevSkim into copilot/investigate-devskim-issue
There was a problem hiding this comment.
Pull request overview
This PR completely rewrites the Visual Studio extension using the modern VisualStudio.Extensibility SDK to fix activation issues in VS2022/2026. The legacy MEF-based ILanguageClient implementation was not properly triggering when files were opened, causing the extension to be non-functional.
Changes:
- Replaced legacy MEF architecture with new VisualStudio.Extensibility SDK's
LanguageServerProvider - Implemented proper settings management using the new SDK's settings API with localized string resources
- Added Windows Job Object support for reliable language server process cleanup
- Enhanced code actions/fixes handling for VS compatibility
- Removed legacy files and simplified the project structure
Reviewed changes
Copilot reviewed 40 out of 42 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| devskim-server-log20260205.txt | |
| Microsoft.DevSkim.sln | Removed unnecessary project configurations (SourceGenerator, ManualGenerator) and platform targets |
| DevSkimExtension.cs | New extension entry point using VS Extensibility SDK |
| DevSkimLanguageServerProvider.cs | New language server provider implementation with process management and settings handling |
| DevSkimSettingDefinitions.cs | Settings definitions using new SDK's declarative API |
| string-resources.json | Localized display names and descriptions for all settings |
| Microsoft.DevSkim.VisualStudio.csproj | Modernized project file using SDK-style format with new dependencies |
| Program.cs (LanguageServer) | Added support for initializationOptions to receive settings from VS client |
| CodeActionHandler.cs | New handler for textDocument/codeAction requests (VS compatibility) |
| TextDocumentSyncHandler.cs | Enhanced to register code fixes with CodeActionHandler |
| StaticScannerSettings.cs | Added proper default initialization for scanner options |
| PortableScannerSettings.cs | Added default values for settings properties |
| Multiple deleted files | Removed legacy MEF-based files, old settings management, and generator projects |
| .gitignore | Added Server folder to ignore list |
Files not reviewed (1)
- DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/Properties/Resources.Designer.cs: Language not supported
Comments suppressed due to low confidence (5)
DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/Program.cs:44
- These lines contain debug/test code that should be removed before merging:
- Line 43: Unused variable
thingwith a hardcoded URL - Line 44: MD5.Create() is called but never used, and MD5 is a deprecated cryptographic algorithm
This appears to be leftover debug code. Please remove these lines as they serve no functional purpose and the MD5 usage triggers security concerns even though it's not actually being used.
var thing = "http://test.com";
MD5 mD5 = MD5.Create();
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:390
- Replace this call with a call to managed code if possible.
NativeMethods.SetInformationJobObject(_jobHandle, 9 /* JobObjectExtendedLimitInformation */, pExtendedInfo, (uint)length);
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:409
- Replace this call with a call to managed code if possible.
NativeMethods.AssignProcessToJobObject(_jobHandle, process.Handle);
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:435
- Minimise the use of unmanaged code.
public static extern bool SetInformationJobObject(SafeHandle hJob, int jobObjectInfoClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:438
- Minimise the use of unmanaged code.
public static extern bool AssignProcessToJobObject(SafeHandle hJob, IntPtr hProcess);
|
|
||
| using global::Microsoft.Extensions.DependencyInjection; | ||
| using global::Microsoft.VisualStudio.Extensibility; | ||
| using System.Security.Cryptography; |
There was a problem hiding this comment.
The using System.Security.Cryptography; import on line 8 is unused and should be removed. There's no cryptographic code in this file.
| using System.Security.Cryptography; |
DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/CodeActionHandler.cs
Outdated
Show resolved
Hide resolved
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs
Show resolved
Hide resolved
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
- Replace foreach loop with .Select() in CodeActionHandler.cs - Remove unused MD5 and test code from Program.cs Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
…m/microsoft/DevSkim into copilot/investigate-devskim-issue
- Added XML documentation explaining why native interop is necessary - Added code analysis suppression with justification - Changed method visibility to internal for better encapsulation Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Applied changes in commit ed6cf52:
The P/Invoke code for Job Objects cannot be replaced with managed code because .NET doesn't provide a managed API for this Windows kernel feature. The native interop is necessary to ensure child processes are terminated when VS exits unexpectedly. |
…m/microsoft/DevSkim into copilot/investigate-devskim-issue
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 42 out of 44 changed files in this pull request and generated 4 comments.
Files not reviewed (1)
- DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/Properties/Resources.Designer.cs: Language not supported
Comments suppressed due to low confidence (4)
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:390
- Replace this call with a call to managed code if possible.
NativeMethods.SetInformationJobObject(_jobHandle, 9 /* JobObjectExtendedLimitInformation */, pExtendedInfo, (uint)length);
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:409
- Replace this call with a call to managed code if possible.
NativeMethods.AssignProcessToJobObject(_jobHandle, process.Handle);
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:442
- Minimise the use of unmanaged code.
internal static extern bool SetInformationJobObject(SafeHandle hJob, int jobObjectInfoClass, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs:445
- Minimise the use of unmanaged code.
internal static extern bool AssignProcessToJobObject(SafeHandle hJob, IntPtr hProcess);
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs
Outdated
Show resolved
Hide resolved
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs
Outdated
Show resolved
Hide resolved
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs
Show resolved
Hide resolved
DevSkim-DotNet/Microsoft.DevSkim.VisualStudio/DevSkimLanguageServerProvider.cs
Show resolved
Hide resolved
…ings (eslint, @humanwhocodes/config-array, @humanwhocodes/object-schema, rimraf, glob@7, inflight). Remaining 2 warnings are transitive deps of @vscode/vsce. - Upgrade eslint ^8.8.0 → ^9.0.0 - Upgrade @typescript-eslint/eslint-plugin and parser ^5.10.1 → ^8.0.0 - Add typescript-eslint package for flat config support - Replace .eslintrc.js + .eslintignore with eslint.config.mjs - Update lint script to remove deprecated --ext flag - Auto-fix lint errors in client/devSkimFixer.ts (var→const, missing semicolon) - Remove stale eslint-disable directive in devskimSettings.ts
- Added class-level _disposeCts that is cancelled in Dispose method - Updated SubscribeAsync calls to use _disposeCts.Token instead of CancellationToken.None - Added try/catch for OperationCanceledException to handle disposal during initialization Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Rewrite the Visual Studio extension using the new VisualStudio.Extensibility SDK for Visual Studio 2022/2026 compatibility.
Problem
The VS2022 DevSkim extension was not functioning properly - the language server was not being activated when opening files. The root cause was that the legacy MEF-based
ILanguageClientimplementation using[ContentType("code")]did not properly trigger activation in Visual Studio.Solution
Completely rewrote the extension using the modern VisualStudio.Extensibility SDK:
ILanguageClientwithLanguageServerProviderfrom the new VS Extensibility SDKDocumentFilter.FromDocumentType("text")for broad file type supportChanges
DevSkimLanguageClient.cs,SettingsChangedNotifier.cs,VisualStudioSettingsManager.cs, etc.DevSkimExtension.cs- Extension entry point using new SDKDevSkimLanguageServerProvider.cs- Language server provider implementationTesting
The extension now properly:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.