Skip to content

Commit

Permalink
Merge pull request #2044 from OmniSharp/feature/lsp-3.16
Browse files Browse the repository at this point in the history
Updated to the latest beta of lsp.  Spec version 3.16
  • Loading branch information
filipw authored Jan 25, 2021
2 parents aaf1fef + 3d120f4 commit 63834ec
Show file tree
Hide file tree
Showing 24 changed files with 444 additions and 145 deletions.
4 changes: 2 additions & 2 deletions build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<PackageReference Update="NuGet.ProjectModel" Version="$(NuGetPackageVersion)" />
<PackageReference Update="NuGet.Versioning" Version="$(NuGetPackageVersion)" />

<PackageReference Update="OmniSharp.Extensions.LanguageServer" Version="0.18.3" />
<PackageReference Update="OmniSharp.Extensions.LanguageProtocol.Testing" Version="0.18.3" />
<PackageReference Update="OmniSharp.Extensions.LanguageServer" Version="0.19.0-beta0004" />
<PackageReference Update="OmniSharp.Extensions.LanguageProtocol.Testing" Version="0.19.0-beta0004" />

<PackageReference Update="SQLitePCLRaw.bundle_green" Version="1.1.2" />
<PackageReference Update="System.Collections.Immutable" Version="1.4.0" />
Expand Down
4 changes: 2 additions & 2 deletions build/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
Expand All @@ -16,7 +16,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/OmniSharp/omnisharp-roslyn.git</RepositoryUrl>

<OutputPath>$([System.IO.Path]::GetFullPath('$(RepositoryRootDirectory)bin\$(Configuration)\$(MSBuildProjectName)'))\</OutputPath>
<BaseIntermediateOutputPath>$([System.IO.Path]::GetFullPath('$(RepositoryRootDirectory)bin\obj\$(MSBuildProjectName)'))\</BaseIntermediateOutputPath>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class DocumentVersions
}

public void Update(VersionedTextDocumentIdentifier identifier)
{
_documentVersions.AddOrUpdate(identifier.Uri, identifier.Version, (uri, i) => identifier.Version);
}

public void Update(OptionalVersionedTextDocumentIdentifier identifier)
{
_documentVersions.AddOrUpdate(identifier.Uri, identifier.Version ?? 0, (uri, i) => identifier.Version ?? 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(
private readonly ExecuteCommandRegistrationOptions _executeCommandRegistrationOptions;
private ExecuteCommandCapability _executeCommandCapability;
private Mef.IRequestHandler<RunCodeActionRequest, RunCodeActionResponse> _runActionHandler;
private readonly DocumentSelector _documentSelector;
private readonly ISerializer _serializer;
private readonly ILanguageServer _server;
private readonly DocumentVersions _documentVersions;
Expand All @@ -50,17 +51,10 @@ public OmniSharpCodeActionHandler(
ISerializer serializer,
ILanguageServer server,
DocumentVersions documentVersions)
: base(new CodeActionRegistrationOptions()
{
DocumentSelector = documentSelector,
CodeActionKinds = new Container<CodeActionKind>(
CodeActionKind.SourceOrganizeImports,
CodeActionKind.Refactor,
CodeActionKind.RefactorExtract),
})
{
_getActionsHandler = getActionsHandler;
_runActionHandler = runActionHandler;
_documentSelector = documentSelector;
_serializer = serializer;
_server = server;
_documentVersions = documentVersions;
Expand All @@ -87,7 +81,7 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
foreach (var ca in omnisharpResponse.CodeActions)
{
CodeActionKind kind;
if (ca.Identifier.StartsWith("using ")) { kind = CodeActionKind.SourceOrganizeImports; }
if (ca.Identifier.StartsWith("using ")) { kind = CodeActionKind.QuickFix; }
else if (ca.Identifier.StartsWith("Inline ")) { kind = CodeActionKind.RefactorInline; }
else if (ca.Identifier.StartsWith("Extract ")) { kind = CodeActionKind.RefactorExtract; }
else if (ca.Identifier.StartsWith("Change ")) { kind = CodeActionKind.QuickFix; }
Expand All @@ -101,14 +95,14 @@ public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams
Diagnostics = new Container<Diagnostic>(),
Edit = new WorkspaceEdit(),
Command = Command.Create("omnisharp/executeCodeAction")
.WithTitle(ca.Name)
.WithArguments(new CommandData()
{
Uri = request.TextDocument.Uri,
Identifier = ca.Identifier,
Name = ca.Name,
Range = request.Range,
})
with { Title = ca.Name }
});
}

Expand All @@ -124,7 +118,7 @@ public override Task<CodeAction> Handle(CodeAction request, CancellationToken ca
public async Task<Unit> Handle(ExecuteCommandParams request, CancellationToken cancellationToken)
{
Debug.Assert(request.Command == "omnisharp/executeCodeAction");
var data = request.Arguments[0].ToObject<CommandData>(_serializer.JsonSerializer);
var data = request.ExtractArguments<CommandData>(_serializer);

var omnisharpCaRequest = new RunCodeActionRequest {
Identifier = data.Identifier,
Expand All @@ -142,7 +136,7 @@ public async Task<Unit> Handle(ExecuteCommandParams request, CancellationToken c
{
var edit = Helpers.ToWorkspaceEdit(
omnisharpCaResponse.Changes,
_server.ClientSettings.Capabilities.Workspace.WorkspaceEdit.Value,
_server.ClientSettings.Capabilities.Workspace!.WorkspaceEdit.Value,
_documentVersions
);
;
Expand All @@ -168,7 +162,22 @@ class CommandData
public Range Range { get; set;}
}

ExecuteCommandRegistrationOptions IRegistration<ExecuteCommandRegistrationOptions> .GetRegistrationOptions() => _executeCommandRegistrationOptions;
void ICapability<ExecuteCommandCapability>.SetCapability(ExecuteCommandCapability capability) => _executeCommandCapability = capability;
ExecuteCommandRegistrationOptions IRegistration<ExecuteCommandRegistrationOptions, ExecuteCommandCapability>.GetRegistrationOptions(ExecuteCommandCapability capability, ClientCapabilities clientCapabilities)
{
_executeCommandCapability = capability;
return _executeCommandRegistrationOptions;
}

protected override CodeActionRegistrationOptions CreateRegistrationOptions(CodeActionCapability capability, ClientCapabilities clientCapabilities)
{
return new CodeActionRegistrationOptions()
{
DocumentSelector = _documentSelector,
CodeActionKinds = new Container<CodeActionKind>(
CodeActionKind.SourceOrganizeImports,
CodeActionKind.Refactor,
CodeActionKind.RefactorExtract),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace OmniSharp.LanguageServerProtocol.Handlers
{
internal sealed class OmniSharpCodeLensHandler : CodeLensHandler
internal sealed class OmniSharpCodeLensHandler : CodeLensHandlerBase
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
Expand All @@ -33,22 +33,19 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)

private readonly Mef.IRequestHandler<MembersTreeRequest, FileMemberTree> _membersAsTreeHandler;
private readonly Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse> _findUsagesHandler;
private readonly DocumentSelector _documentSelector;

public OmniSharpCodeLensHandler(
Mef.IRequestHandler<MembersTreeRequest, FileMemberTree> membersAsTreeHandler,
Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse> findUsagesHandler,
DocumentSelector documentSelector)
: base(new CodeLensRegistrationOptions()
{
DocumentSelector = documentSelector,
ResolveProvider = true
})
{
_membersAsTreeHandler = membersAsTreeHandler;
_findUsagesHandler = findUsagesHandler;
_documentSelector = documentSelector;
}

public async override Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken token)
public override async Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken token)
{
var omnisharpRequest = new MembersTreeRequest()
{
Expand All @@ -66,7 +63,7 @@ public async override Task<CodeLensContainer> Handle(CodeLensParams request, Can
return codeLenseContainer;
}

public async override Task<CodeLens> Handle(CodeLens request, CancellationToken token)
public override async Task<CodeLens> Handle(CodeLens request, CancellationToken token)
{
var omnisharpRequest = new FindUsagesRequest
{
Expand All @@ -86,7 +83,7 @@ public async override Task<CodeLens> Handle(CodeLens request, CancellationToken
ContractResolver = new CamelCasePropertyNamesContractResolver()
};

request.Command = new Command
request = request with { Command = new Command
{
Title = length == 1 ? "1 reference" : $"{length} references",
Name = "omnisharp/client/findReferences",
Expand All @@ -96,12 +93,12 @@ public async override Task<CodeLens> Handle(CodeLens request, CancellationToken
JObject.FromObject(
new Location
{
Uri = request.Data.ToObject<Uri>(),
Uri = request.Data.ToObject<Uri>()!,
Range = request.Range,
},
jsonCamelCaseContract)
}),
};
} };

return request;
}
Expand All @@ -127,5 +124,14 @@ private static void ToCodeLens(TextDocumentIdentifier textDocument, FileMemberEl
}
}
}

protected override CodeLensRegistrationOptions CreateRegistrationOptions(CodeLensCapability capability, ClientCapabilities clientCapabilities)
{
return new CodeLensRegistrationOptions()
{
DocumentSelector = _documentSelector,
ResolveProvider = true
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace OmniSharp.LanguageServerProtocol.Handlers
{
class OmniSharpCompletionHandler : CompletionHandler
class OmniSharpCompletionHandler : CompletionHandlerBase
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
Expand All @@ -23,6 +23,7 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<AutoCompleteRequest, IEnumerable<AutoCompleteResponse>> _autoCompleteHandler;
private readonly DocumentSelector _documentSelector;

private static readonly IDictionary<string, CompletionItemKind> _kind = new Dictionary<string, CompletionItemKind>{
// types
Expand All @@ -40,7 +41,7 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
// members
{ "Const", CompletionItemKind.Constant },
{ "EnumMember", CompletionItemKind.Enum },
{ "Event", CompletionItemKind.Event },
{ "Event", CompletionItemKind.Event },
{ "Field", CompletionItemKind.Field },
{ "Method", CompletionItemKind.Method },
{ "Property", CompletionItemKind.Property },
Expand All @@ -65,15 +66,9 @@ private static CompletionItemKind GetCompletionItemKind(string key)
}

public OmniSharpCompletionHandler(Mef.IRequestHandler<AutoCompleteRequest, IEnumerable<AutoCompleteResponse>> autoCompleteHandler, DocumentSelector documentSelector)
: base(new CompletionRegistrationOptions()
{
DocumentSelector = documentSelector,
// TODO: Come along and add a service for getting autocompletion details after the fact.
ResolveProvider = false,
TriggerCharacters = new[] { ".", },
})
{
_autoCompleteHandler = autoCompleteHandler;
_documentSelector = documentSelector;
}

public async override Task<CompletionList> Handle(CompletionParams request, CancellationToken token)
Expand Down Expand Up @@ -126,7 +121,7 @@ public async override Task<CompletionList> Handle(CompletionParams request, Canc
if (overloadCount > 0)
{
// indicate that there is more
suggestion.Detail = $"{suggestion.Detail} (+ {overloadCount} overload(s))";
suggestion = suggestion with { Detail = $"{suggestion.Detail} (+ {overloadCount} overload(s))" };
}

result.Add(suggestion);
Expand All @@ -139,5 +134,16 @@ public override Task<CompletionItem> Handle(CompletionItem request, Cancellation
{
return Task.FromResult(request);
}

protected override CompletionRegistrationOptions CreateRegistrationOptions(CompletionCapability capability, ClientCapabilities clientCapabilities)
{
return new CompletionRegistrationOptions()
{
DocumentSelector = _documentSelector,
// TODO: Come along and add a service for getting autocompletion details after the fact.
ResolveProvider = false,
TriggerCharacters = new[] {".",},
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace OmniSharp.LanguageServerProtocol.Handlers
{
class OmniSharpDefinitionHandler : DefinitionHandler
class OmniSharpDefinitionHandler : DefinitionHandlerBase
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
Expand All @@ -22,17 +22,15 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<GotoDefinitionRequest, GotoDefinitionResponse> _definitionHandler;
private readonly DocumentSelector _documentSelector;

public OmniSharpDefinitionHandler(Mef.IRequestHandler<GotoDefinitionRequest, GotoDefinitionResponse> definitionHandler, DocumentSelector documentSelector)
: base(new DefinitionRegistrationOptions()
{
DocumentSelector = documentSelector
})
{
_definitionHandler = definitionHandler;
_documentSelector = documentSelector;
}

public async override Task<LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken token)
public override async Task<LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken token)
{
var omnisharpRequest = new GotoDefinitionRequest()
{
Expand All @@ -54,5 +52,13 @@ public async override Task<LocationOrLocationLinks> Handle(DefinitionParams requ
Range = ToRange((omnisharpResponse.Column, omnisharpResponse.Line))
});
}

protected override DefinitionRegistrationOptions CreateRegistrationOptions(DefinitionCapability capability, ClientCapabilities clientCapabilities)
{
return new DefinitionRegistrationOptions()
{
DocumentSelector = _documentSelector
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using System.Threading;
using System.Threading.Tasks;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Models.Format;

namespace OmniSharp.LanguageServerProtocol.Handlers
{
internal sealed class OmniSharpDocumentFormatRangeHandler : DocumentRangeFormattingHandler
internal sealed class OmniSharpDocumentFormatRangeHandler : DocumentRangeFormattingHandlerBase
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
Expand All @@ -22,17 +23,15 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> _formatRangeHandler;
private readonly DocumentSelector _documentSelector;

public OmniSharpDocumentFormatRangeHandler(Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> formatRangeHandler, DocumentSelector documentSelector) : base(
new DocumentRangeFormattingRegistrationOptions()
{
DocumentSelector = documentSelector,
})
public OmniSharpDocumentFormatRangeHandler(Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> formatRangeHandler, DocumentSelector documentSelector)
{
_formatRangeHandler = formatRangeHandler;
_documentSelector = documentSelector;
}

public async override Task<TextEditContainer> Handle(DocumentRangeFormattingParams request, CancellationToken cancellationToken)
public override async Task<TextEditContainer> Handle(DocumentRangeFormattingParams request, CancellationToken cancellationToken)
{
var omnisharpRequest = new FormatRangeRequest()
{
Expand All @@ -50,5 +49,13 @@ public async override Task<TextEditContainer> Handle(DocumentRangeFormattingPara
Range = new Range(new Position(change.StartLine, change.StartColumn), new Position(change.EndLine, change.EndColumn))
}).ToArray();
}

protected override DocumentRangeFormattingRegistrationOptions CreateRegistrationOptions(DocumentRangeFormattingCapability capability, ClientCapabilities clientCapabilities)
{
return new DocumentRangeFormattingRegistrationOptions()
{
DocumentSelector = _documentSelector,
};
}
}
}
Loading

0 comments on commit 63834ec

Please sign in to comment.