From e63cbd1ecd612cc24ba7a9a41a1018ad6a596cb2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 05:02:21 +0000 Subject: [PATCH 1/3] Initial plan From 3dd24be69d272d3a5c2f7229addc319fefba84f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 05:11:49 +0000 Subject: [PATCH 2/3] Add on-demand scan command and auto-rescan on settings change Co-authored-by: gfs <98900+gfs@users.noreply.github.com> --- Changelog.md | 8 +++ .../Messages.cs | 1 + .../Program.cs | 1 + .../RescanHandler.cs | 51 +++++++++++++++++++ .../TextDocumentSyncHandler.cs | 10 +++- DevSkim-VSCode-Plugin/client/extension.ts | 22 ++++++++ DevSkim-VSCode-Plugin/package.json | 7 ++- 7 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/RescanHandler.cs diff --git a/Changelog.md b/Changelog.md index 4d112400..cd3d1f73 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0.76] - 2026-02-14 +### Added +- Added on-demand scan command `DevSkim: Scan All Open Files` for VS Code extension to manually trigger rescanning of all open documents +- Automatically rescan all open documents when DevSkim settings are changed +- Added custom LSP request handler `devskim/rescanDocument` to Language Server to support on-demand rescanning + + ## [1.0.75] - 2026-02-06 ### Changed - Removed unnecessary uninstall/reinstall of @vscode/vsce from postinstall script in VSCode plugin diff --git a/DevSkim-DotNet/Microsoft.DevSkim.LanguageProtoInterop/Messages.cs b/DevSkim-DotNet/Microsoft.DevSkim.LanguageProtoInterop/Messages.cs index 5335acfe..fb8e52cb 100644 --- a/DevSkim-DotNet/Microsoft.DevSkim.LanguageProtoInterop/Messages.cs +++ b/DevSkim-DotNet/Microsoft.DevSkim.LanguageProtoInterop/Messages.cs @@ -9,5 +9,6 @@ public static class DevSkimMessages public const string FileVersion = "devskim/fileversion"; public const string CodeFixMapping = "devskim/codefixmapping"; public const string SetServerSettings = "devskim/setSettings"; + public const string RescanDocument = "devskim/rescanDocument"; } } diff --git a/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/Program.cs b/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/Program.cs index 38330965..dd05f8a0 100644 --- a/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/Program.cs +++ b/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/Program.cs @@ -54,6 +54,7 @@ static async Task Main(string[] args) .WithHandler() .WithHandler() .WithHandler() + .WithHandler() .WithServices(x => x.AddLogging(b => b.SetMinimumLevel(LogLevel.Debug))) .WithConfigurationSection(ConfigHelpers.Section) .OnInitialize( diff --git a/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/RescanHandler.cs b/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/RescanHandler.cs new file mode 100644 index 00000000..2a5e0434 --- /dev/null +++ b/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/RescanHandler.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using MediatR; +using Microsoft.DevSkim.LanguageProtoInterop; +using Microsoft.Extensions.Logging; +using OmniSharp.Extensions.JsonRpc; +using OmniSharp.Extensions.LanguageServer.Protocol; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; + +namespace DevSkim.LanguageServer +{ + [Method(DevSkimMessages.RescanDocument, Direction.ClientToServer)] + public record RescanDocumentParams : IRequest + { + public DocumentUri? Uri { get; init; } + public string? Text { get; init; } + public int? Version { get; init; } + } + + /// + /// Handles requests from the client to rescan a document on demand + /// + public class RescanHandler : IJsonRpcRequestHandler + { + private readonly ILogger _logger; + private readonly TextDocumentSyncHandler _syncHandler; + + public RescanHandler(ILogger logger, TextDocumentSyncHandler syncHandler) + { + _logger = logger; + _syncHandler = syncHandler; + } + + async Task IRequestHandler.Handle(RescanDocumentParams request, CancellationToken cancellationToken) + { + _logger.LogDebug($"RescanHandler: Received rescan request for {request.Uri}"); + + if (request.Uri is null || request.Text is null) + { + _logger.LogWarning("RescanHandler: Uri or Text is null"); + return Unit.Value; + } + + _logger.LogDebug($"RescanHandler: Rescanning document {request.Uri}"); + await _syncHandler.ScanDocumentAsync(request.Text, request.Version, request.Uri); + + return Unit.Value; + } + } +} diff --git a/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/TextDocumentSyncHandler.cs b/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/TextDocumentSyncHandler.cs index 7ea29b6c..efa97c35 100644 --- a/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/TextDocumentSyncHandler.cs +++ b/DevSkim-DotNet/Microsoft.DevSkim.LanguageServer/TextDocumentSyncHandler.cs @@ -16,7 +16,7 @@ namespace DevSkim.LanguageServer { - internal class TextDocumentSyncHandler : TextDocumentSyncHandlerBase + public class TextDocumentSyncHandler : TextDocumentSyncHandlerBase { private readonly ILogger _logger; private readonly ILanguageServerFacade _facade; @@ -31,6 +31,14 @@ public TextDocumentSyncHandler(ILogger logger, ILanguag public TextDocumentSyncKind Change { get; } = TextDocumentSyncKind.Full; + /// + /// Public method to trigger document scanning on demand + /// + public async Task ScanDocumentAsync(string text, int? version, DocumentUri uri) + { + await GenerateDiagnosticsForTextDocumentAsync(text, version, uri); + } + private async Task GenerateDiagnosticsForTextDocumentAsync(string text, int? version, DocumentUri uri) { if (string.IsNullOrEmpty(text)) diff --git a/DevSkim-VSCode-Plugin/client/extension.ts b/DevSkim-VSCode-Plugin/client/extension.ts index 7a092d26..6b0a3313 100644 --- a/DevSkim-VSCode-Plugin/client/extension.ts +++ b/DevSkim-VSCode-Plugin/client/extension.ts @@ -22,6 +22,19 @@ import { FileVersion } from './common/fileVersion'; let client: LanguageClient; +// Helper to rescan documents via custom server request +function rescanOpenDocuments() { + vscode.workspace.textDocuments + .filter(doc => selectors.some(s => vscode.languages.match(s, doc) > 0)) + .forEach(doc => { + client?.sendRequest('devskim/rescanDocument', { + uri: doc.uri.toString(), + text: doc.getText(), + version: doc.version + }); + }); +} + async function resolveDotNetPath(): Promise { const result = await vscode.commands.executeCommand( "dotnet.acquire", @@ -72,6 +85,14 @@ export function activate(context: ExtensionContext) { }) ); + // Register manual scan command + context.subscriptions.push( + vscode.commands.registerCommand('devskim.scanWorkspace', () => { + rescanOpenDocuments(); + vscode.window.showInformationMessage('DevSkim: Rescanned all open files'); + }) + ); + // The server bridge is implemented in .NET const serverModule = vscode.Uri.joinPath(context.extensionUri, 'devskimBinaries', 'Microsoft.DevSkim.LanguageServer.dll'); @@ -136,6 +157,7 @@ export function activate(context: ExtensionContext) { // Triggers server to query for client config. // Hacky, but vscode insists a pull model should be used over a push model for transmitting settings. client.sendNotification(DidChangeConfigurationNotification.type, { settings: "" }); + rescanOpenDocuments(); } }); diff --git a/DevSkim-VSCode-Plugin/package.json b/DevSkim-VSCode-Plugin/package.json index 3488aa4e..d13ca133 100644 --- a/DevSkim-VSCode-Plugin/package.json +++ b/DevSkim-VSCode-Plugin/package.json @@ -72,7 +72,12 @@ ], "main": "./client/out/extension.js", "contributes": { - "commands": [], + "commands": [ + { + "command": "devskim.scanWorkspace", + "title": "DevSkim: Scan All Open Files" + } + ], "configuration": [ { "order": 10, From f0f8220052ef1999920d96382dd04cabb343628b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 05:12:54 +0000 Subject: [PATCH 3/3] Add error handling for rescan requests Co-authored-by: gfs <98900+gfs@users.noreply.github.com> --- DevSkim-VSCode-Plugin/client/extension.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DevSkim-VSCode-Plugin/client/extension.ts b/DevSkim-VSCode-Plugin/client/extension.ts index 6b0a3313..74cbfd99 100644 --- a/DevSkim-VSCode-Plugin/client/extension.ts +++ b/DevSkim-VSCode-Plugin/client/extension.ts @@ -31,6 +31,8 @@ function rescanOpenDocuments() { uri: doc.uri.toString(), text: doc.getText(), version: doc.version + }).catch(err => { + console.error(`DevSkim: Failed to rescan ${doc.uri.toString()}`, err); }); }); }