diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs index eb5af4806..053e6a2b0 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.Logging; using Microsoft.PowerShell.EditorServices.Services; using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using Microsoft.PowerShell.EditorServices.Utility; using Newtonsoft.Json.Linq; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; @@ -42,7 +43,7 @@ public CodeActionHandler(ILoggerFactory factory, AnalysisService analysisService _workspaceService = workspaceService; _registrationOptions = new CodeActionRegistrationOptions { - DocumentSelector = new DocumentSelector(new DocumentFilter() { Language = "powershell" }), + DocumentSelector = LspUtils.PowerShellDocumentSelector, CodeActionKinds = s_supportedCodeActions }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs index 80aa5e671..3eab5a280 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs @@ -14,6 +14,7 @@ using Microsoft.PowerShell.EditorServices.Logging; using Microsoft.PowerShell.EditorServices.Services; using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using Microsoft.PowerShell.EditorServices.Utility; using OmniSharp.Extensions.LanguageServer.Protocol; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; @@ -23,13 +24,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { internal class CodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; @@ -47,7 +41,7 @@ CodeLensRegistrationOptions IRegistration.GetRegist { return new CodeLensRegistrationOptions { - DocumentSelector = _documentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector, ResolveProvider = true }; } @@ -65,7 +59,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions { - DocumentSelector = _documentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector, }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs index a176af218..104c6bcb6 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs @@ -54,7 +54,7 @@ public CompletionRegistrationOptions GetRegistrationOptions() { return new CompletionRegistrationOptions { - DocumentSelector = new DocumentSelector(new DocumentFilter { Language = "powershell" }), + DocumentSelector = LspUtils.PowerShellDocumentSelector, ResolveProvider = true, TriggerCharacters = new[] { ".", "-", ":", "\\" } }; diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs index a050dce5c..bf500acf3 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs @@ -19,13 +19,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { internal class DefinitionHandler : IDefinitionHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; @@ -46,7 +39,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions { - DocumentSelector = _documentSelector + DocumentSelector = LspUtils.PowerShellDocumentSelector }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs index 2859c57e3..9181e490f 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs @@ -41,7 +41,7 @@ public DocumentHighlightHandler( _symbolsService = symbolService; _registrationOptions = new TextDocumentRegistrationOptions() { - DocumentSelector = new DocumentSelector(new DocumentFilter() { Language = "powershell" } ) + DocumentSelector = LspUtils.PowerShellDocumentSelector }; _logger.LogInformation("highlight handler loaded"); } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs index ae12cbc39..f702c629b 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs @@ -24,13 +24,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { internal class DocumentSymbolHandler : IDocumentSymbolHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly WorkspaceService _workspaceService; @@ -54,7 +47,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions { - DocumentSelector = _documentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector, }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs index 08c37536b..fd9769e15 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging; using Microsoft.PowerShell.EditorServices.Services; using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using Microsoft.PowerShell.EditorServices.Utility; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Server; @@ -17,13 +18,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { internal class FoldingRangeHandler : IFoldingRangeHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter() - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly ConfigurationService _configurationService; private readonly WorkspaceService _workspaceService; @@ -40,7 +34,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions() { - DocumentSelector = _documentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector, }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs index d3f4a467a..682b1439c 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.PowerShell.EditorServices.Services; +using Microsoft.PowerShell.EditorServices.Utility; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Server; @@ -15,13 +16,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { internal class DocumentFormattingHandler : IDocumentFormattingHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter() - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly AnalysisService _analysisService; private readonly ConfigurationService _configurationService; @@ -40,7 +34,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions { - DocumentSelector = _documentSelector + DocumentSelector = LspUtils.PowerShellDocumentSelector }; } @@ -93,13 +87,6 @@ public void SetCapability(DocumentFormattingCapability capability) internal class DocumentRangeFormattingHandler : IDocumentRangeFormattingHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter() - { - Pattern = "**/*.ps*1" - } - ); - private readonly ILogger _logger; private readonly AnalysisService _analysisService; private readonly ConfigurationService _configurationService; @@ -118,7 +105,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions { - DocumentSelector = _documentSelector + DocumentSelector = LspUtils.PowerShellDocumentSelector }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs index 9a968fdc2..8ab57413a 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs @@ -10,6 +10,7 @@ using Microsoft.PowerShell.EditorServices.Services; using Microsoft.PowerShell.EditorServices.Services.Symbols; using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using Microsoft.PowerShell.EditorServices.Utility; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Server; @@ -18,13 +19,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { internal class HoverHandler : IHoverHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; @@ -48,7 +42,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions { - DocumentSelector = _documentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector, }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs index 36f8f5dfe..9917c557f 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs @@ -19,13 +19,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { class ReferencesHandler : IReferencesHandler { - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter() - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; @@ -42,7 +35,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() { return new TextDocumentRegistrationOptions { - DocumentSelector = _documentSelector + DocumentSelector = LspUtils.PowerShellDocumentSelector }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs index f2acaf562..f21ca09b0 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs @@ -11,6 +11,7 @@ using Microsoft.PowerShell.EditorServices.Services; using Microsoft.PowerShell.EditorServices.Services.Symbols; using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using Microsoft.PowerShell.EditorServices.Utility; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Server; @@ -20,14 +21,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers internal class SignatureHelpHandler : ISignatureHelpHandler { private static readonly SignatureInformation[] s_emptySignatureResult = Array.Empty(); - - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter() - { - Language = "powershell" - } - ); - private readonly ILogger _logger; private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; @@ -51,7 +44,7 @@ public SignatureHelpRegistrationOptions GetRegistrationOptions() { return new SignatureHelpRegistrationOptions { - DocumentSelector = _documentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector, // A sane default of " ". We may be able to include others like "-". TriggerCharacters = new Container(" ") }; diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs index a8d10fbae..784593d83 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs @@ -15,6 +15,7 @@ using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Server; using OmniSharp.Extensions.LanguageServer.Protocol.Server.Capabilities; +using Microsoft.PowerShell.EditorServices.Utility; namespace Microsoft.PowerShell.EditorServices.Handlers { @@ -25,14 +26,6 @@ class TextDocumentHandler : ITextDocumentSyncHandler private readonly AnalysisService _analysisService; private readonly WorkspaceService _workspaceService; private readonly RemoteFileManagerService _remoteFileManagerService; - - private readonly DocumentSelector _documentSelector = new DocumentSelector( - new DocumentFilter() - { - Language = "powershell" - } - ); - private SynchronizationCapability _capability; public TextDocumentSyncKind Change => TextDocumentSyncKind.Incremental; @@ -72,7 +65,7 @@ TextDocumentChangeRegistrationOptions IRegistration.G { return new TextDocumentRegistrationOptions() { - DocumentSelector = _documentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector, }; } @@ -138,7 +131,7 @@ TextDocumentSaveRegistrationOptions IRegistration new DocumentSelector( + DocumentFilter.ForLanguage("powershell"), + DocumentFilter.ForLanguage("pwsh"), + + // The vim extension sets all PowerShell files as language "ps1" so this + // makes sure we track those. + DocumentFilter.ForLanguage("ps1"), + DocumentFilter.ForLanguage("psm1"), + DocumentFilter.ForLanguage("psd1"), + + // Also specify the file extensions to be thorough + // This won't handle untitled files which is why we have to do the ones above. + DocumentFilter.ForPattern("**/*.ps*1") + ); + } +}