Skip to content

Switch to better document selecting #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -47,7 +41,7 @@ CodeLensRegistrationOptions IRegistration<CodeLensRegistrationOptions>.GetRegist
{
return new CodeLensRegistrationOptions
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
ResolveProvider = true
};
}
Expand All @@ -65,7 +59,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public CompletionRegistrationOptions GetRegistrationOptions()
{
return new CompletionRegistrationOptions
{
DocumentSelector = new DocumentSelector(new DocumentFilter { Language = "powershell" }),
DocumentSelector = LspUtils.PowerShellDocumentSelector,
ResolveProvider = true,
TriggerCharacters = new[] { ".", "-", ":", "\\" }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,7 +39,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = _documentSelector
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -54,7 +47,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -40,7 +34,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions()
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -40,7 +34,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = _documentSelector
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}

Expand Down Expand Up @@ -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;
Expand All @@ -118,7 +105,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = _documentSelector
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -48,7 +42,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,7 +35,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = _documentSelector
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,14 +21,6 @@ namespace Microsoft.PowerShell.EditorServices.Handlers
internal class SignatureHelpHandler : ISignatureHelpHandler
{
private static readonly SignatureInformation[] s_emptySignatureResult = Array.Empty<SignatureInformation>();

private readonly DocumentSelector _documentSelector = new DocumentSelector(
new DocumentFilter()
{
Language = "powershell"
}
);

private readonly ILogger _logger;
private readonly SymbolsService _symbolsService;
private readonly WorkspaceService _workspaceService;
Expand All @@ -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<string>(" ")
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -72,7 +65,7 @@ TextDocumentChangeRegistrationOptions IRegistration<TextDocumentChangeRegistrati
{
return new TextDocumentChangeRegistrationOptions()
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
SyncKind = Change
};
}
Expand Down Expand Up @@ -101,7 +94,7 @@ TextDocumentRegistrationOptions IRegistration<TextDocumentRegistrationOptions>.G
{
return new TextDocumentRegistrationOptions()
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
};
}

Expand Down Expand Up @@ -138,7 +131,7 @@ TextDocumentSaveRegistrationOptions IRegistration<TextDocumentSaveRegistrationOp
{
return new TextDocumentSaveRegistrationOptions()
{
DocumentSelector = _documentSelector,
DocumentSelector = LspUtils.PowerShellDocumentSelector,
IncludeText = true
};
}
Expand Down
27 changes: 27 additions & 0 deletions src/PowerShellEditorServices/Utility/LspUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using OmniSharp.Extensions.LanguageServer.Protocol.Models;

namespace Microsoft.PowerShell.EditorServices.Utility
{
internal static class LspUtils
{
public static DocumentSelector PowerShellDocumentSelector => 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")
);
}
}