diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs index 116b77c3e..7aa99a69e 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/Diagnostics.cs @@ -71,6 +71,11 @@ public class Diagnostic /// Gets or sets the diagnostic message. /// public string Message { get; set; } + + /// + /// Gets or sets the source of the diagnostic message. + /// + public string Source { get; set; } } } diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index ae132731b..cfe41c0ba 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -27,6 +27,7 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.Server public class LanguageServer : LanguageServerBase { private static CancellationTokenSource existingRequestCancellation; + private readonly static string DiagnosticSourceName = "PowerShellEditorServices"; private bool profilesLoaded; private EditorSession editorSession; @@ -994,7 +995,9 @@ protected async Task HandleCodeActionRequest( { foreach (var diagnostic in codeActionParams.Context.Diagnostics) { - if (markerIndex.TryGetValue(diagnostic.Code, out correction)) + if (string.Equals(diagnostic.Source, DiagnosticSourceName, StringComparison.CurrentCultureIgnoreCase) && + !string.IsNullOrEmpty(diagnostic.Code) && + markerIndex.TryGetValue(diagnostic.Code, out correction)) { codeActionCommands.Add( new CodeActionCommand @@ -1335,9 +1338,9 @@ private static Diagnostic GetDiagnosticFromMarker(ScriptFileMarker scriptFileMar Severity = MapDiagnosticSeverity(scriptFileMarker.Level), Message = scriptFileMarker.Message, Code = Guid.NewGuid().ToString(), + Source = DiagnosticSourceName, Range = new Range { - // TODO: What offsets should I use? Start = new Position { Line = scriptFileMarker.ScriptRegion.StartLineNumber - 1, diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index db1affd8f..b34471697 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -301,13 +301,15 @@ internal static bool IsPathInMemory(string filePath) // When viewing PowerShell files in the Git diff viewer, VS Code // sends the contents of the file at HEAD with a URI that starts // with 'inmemory'. Untitled files which have been marked of - // type PowerShell have a path starting with 'untitled'. Files - // opened from the find/replace view will be prefixed with - // 'private'. + // type PowerShell have a path starting with 'untitled'. return filePath.StartsWith("inmemory") || filePath.StartsWith("untitled") || - filePath.StartsWith("private"); + filePath.StartsWith("private") || + filePath.StartsWith("git"); + + // TODO #342: Remove 'private' and 'git' and then add logic to + // throw when any unsupported file URI scheme is encountered. } private string GetBaseFilePath(string filePath)