Skip to content
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

Upgraded to latest lsp #1562

Merged
merged 14 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<PackageReference Update="Nuget.ProjectModel" Version="$(NuGetPackageVersion)" />
<PackageReference Update="Nuget.Versioning" Version="$(NuGetPackageVersion)" />

<PackageReference Update="OmniSharp.Extensions.LanguageServer" Version="0.12.1" />
<PackageReference Update="OmniSharp.Extensions.LanguageServer" Version="0.13.1" />

<PackageReference Update="SQLitePCLRaw.bundle_green" Version="1.1.2" />
<PackageReference Update="System.Collections.Immutable" Version="1.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OmniSharp.LanguageServerProtocol.Handlers
{
internal sealed class CodeLensHandler : ICodeLensHandler, ICodeLensResolveHandler
internal sealed class OmniSharpCodeLensHandler : CodeLensHandler
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
Expand All @@ -24,26 +24,28 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
Mef.IRequestHandler<MembersTreeRequest, FileMemberTree>,
Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse>>())
{
yield return new CodeLensHandler(membersAsTreeHandler, findUsagesHandler, selector);
yield return new OmniSharpCodeLensHandler(membersAsTreeHandler, findUsagesHandler, selector);
}
}

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

public CodeLensHandler(
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 Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken token)
public async override Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken token)
{
var omnisharpRequest = new MembersTreeRequest()
{
Expand All @@ -61,13 +63,13 @@ public async Task<CodeLensContainer> Handle(CodeLensParams request, Cancellation
return codeLenseContainer;
}

public async Task<CodeLens> Handle(CodeLens request, CancellationToken token)
public async override Task<CodeLens> Handle(CodeLens request, CancellationToken token)
{
var omnisharpRequest = new FindUsagesRequest
{
FileName = Helpers.FromUri(request.Data.ToObject<Uri>()),
Column = (int) request.Range.Start.Character,
Line = (int) request.Range.Start.Line,
Column = (int)request.Range.Start.Character,
Line = (int)request.Range.Start.Line,
OnlyThisFile = false,
ExcludeDefinition = true
};
Expand All @@ -85,21 +87,6 @@ public async Task<CodeLens> Handle(CodeLens request, CancellationToken token)
return request;
}


public CodeLensRegistrationOptions GetRegistrationOptions()
{
return new CodeLensRegistrationOptions()
{
DocumentSelector = _documentSelector,
ResolveProvider = true
};
}

public void SetCapability(CodeLensCapability capability)
{
_capability = capability;
}

private static void ToCodeLens(TextDocumentIdentifier textDocument, FileMemberElement node, List<CodeLens> codeLensContainer)
{
var codeLens = new CodeLens
Expand All @@ -121,12 +108,12 @@ private static void ToCodeLens(TextDocumentIdentifier textDocument, FileMemberEl
}
}

public bool CanResolve(CodeLens value)
public override bool CanResolve(CodeLens value)
{
var textDocumentUri = value.Data.ToObject<Uri>();

return textDocumentUri != null &&
_documentSelector.IsMatch(new TextDocumentAttributes(textDocumentUri, string.Empty));
GetRegistrationOptions().DocumentSelector.IsMatch(new TextDocumentAttributes(textDocumentUri, string.Empty));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@

namespace OmniSharp.LanguageServerProtocol.Handlers
{
class CompletionHandler : ICompletionHandler
class OmniSharpCompletionHandler : CompletionHandler
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{

foreach (var (selector, handler) in handlers
.OfType<Mef.IRequestHandler<AutoCompleteRequest, IEnumerable<AutoCompleteResponse>>>())
if (handler != null)
yield return new CompletionHandler(handler, selector);
yield return new OmniSharpCompletionHandler(handler, selector);
}

private CompletionCapability _capability;
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 Down Expand Up @@ -58,20 +56,26 @@ private static CompletionItemKind GetCompletionItemKind(string key)
{
return CompletionItemKind.Property;
}
if(_kind.TryGetValue(key, out var completionItemKind))
if (_kind.TryGetValue(key, out var completionItemKind))
{
return completionItemKind;
}
return CompletionItemKind.Property;
}

public CompletionHandler(Mef.IRequestHandler<AutoCompleteRequest, IEnumerable<AutoCompleteResponse>> autoCompleteHandler, DocumentSelector documentSelector)
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 Task<CompletionList> Handle(CompletionParams request, CancellationToken token)
public async override Task<CompletionList> Handle(CompletionParams request, CancellationToken token)
{
var omnisharpRequest = new AutoCompleteRequest()
{
Expand All @@ -81,19 +85,20 @@ public async Task<CompletionList> Handle(CompletionParams request, CancellationT
WantKind = true,
WantDocumentationForEveryCompletionResult = true,
WantReturnType = true,
WantSnippet =_capability.CompletionItem?.SnippetSupport ?? false
WantSnippet = Capability.CompletionItem?.SnippetSupport ?? false
};

var omnisharpResponse = await _autoCompleteHandler.Handle(omnisharpRequest);

var completions = new Dictionary<string, List<CompletionItem>>();
foreach (var response in omnisharpResponse)
{
var isSnippet = !string.IsNullOrEmpty(response.Snippet);
var text = isSnippet ? response.Snippet : response.CompletionText;
var isSnippet = !string.IsNullOrEmpty(response.Snippet);
var text = isSnippet ? response.Snippet : response.CompletionText;
var textFormat = isSnippet ? InsertTextFormat.Snippet : InsertTextFormat.PlainText;

var completionItem = new CompletionItem {
var completionItem = new CompletionItem
{
Label = response.CompletionText,
Detail = !string.IsNullOrEmpty(response.ReturnType) ?
response.DisplayText :
Expand All @@ -104,7 +109,7 @@ public async Task<CompletionList> Handle(CompletionParams request, CancellationT
InsertTextFormat = textFormat,
};

if(!completions.ContainsKey(completionItem.Label))
if (!completions.ContainsKey(completionItem.Label))
{
completions[completionItem.Label] = new List<CompletionItem>();
}
Expand All @@ -129,18 +134,14 @@ public async Task<CompletionList> Handle(CompletionParams request, CancellationT
return new CompletionList(result);
}

public CompletionRegistrationOptions GetRegistrationOptions()
public override Task<CompletionItem> Handle(CompletionItem request, CancellationToken cancellationToken)
{
return new CompletionRegistrationOptions()
{
DocumentSelector = _documentSelector,
TriggerCharacters = new[] { "." },
};
throw new NotImplementedException();
}

public void SetCapability(CompletionCapability capability)
public override bool CanResolve(CompletionItem value)
{
_capability = capability;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,27 @@

namespace OmniSharp.LanguageServerProtocol.Handlers
{
class DefinitionHandler : IDefinitionHandler
class OmniSharpDefinitionHandler : DefinitionHandler
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
foreach (var (selector, handler) in handlers.OfType<Mef.IRequestHandler<GotoDefinitionRequest, GotoDefinitionResponse>>())
if (handler != null)
yield return new DefinitionHandler(handler, selector);
yield return new OmniSharpDefinitionHandler(handler, selector);
}

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

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

public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions()
{
DocumentSelector = _documentSelector
};
}

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

public void SetCapability(DefinitionCapability capability)
{
_capability = capability;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OmniSharp.Extensions.JsonRpc;
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
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
foreach (var (selector, handler) in handlers
.OfType<Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse>>())
if (handler != null)
yield return new OmniSharpDocumentFormatRangeHandler(handler, selector);
}

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

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

public async override Task<TextEditContainer> Handle(DocumentRangeFormattingParams request, CancellationToken cancellationToken)
{
var omnisharpRequest = new FormatRangeRequest()
{
FileName = Helpers.FromUri(request.TextDocument.Uri),
Line = Convert.ToInt32(request.Range.Start.Line),
Column = Convert.ToInt32(request.Range.Start.Character),
EndLine = Convert.ToInt32(request.Range.End.Line),
EndColumn = Convert.ToInt32(request.Range.End.Character),
};

var omnisharpResponse = await _formatRangeHandler.Handle(omnisharpRequest);
return omnisharpResponse.Changes.Select(change => new TextEdit()
{
NewText = change.NewText,
Range = new Range(new Position(change.StartLine, change.StartColumn), new Position(change.EndLine, change.EndColumn))
}).ToArray();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Models.CodeFormat;
using OmniSharp.Models.MembersTree;
using OmniSharp.Models.V2.CodeStructure;

namespace OmniSharp.LanguageServerProtocol.Handlers
{
internal sealed class OmniSharpDocumentFormattingHandler : DocumentFormattingHandler
{
public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
{
foreach (var (selector, handler) in handlers
.OfType<Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse>>())
if (handler != null)
yield return new OmniSharpDocumentFormattingHandler(handler, selector);
}

private readonly Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse> _codeFormatHandler;

public OmniSharpDocumentFormattingHandler(Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse> codeFormatHandler, DocumentSelector documentSelector) : base(new TextDocumentRegistrationOptions()
{
DocumentSelector = documentSelector,
})
{
_codeFormatHandler = codeFormatHandler;
}

public async override Task<TextEditContainer> Handle(DocumentFormattingParams request, CancellationToken cancellationToken)
{
var omnisharpRequest = new CodeFormatRequest()
{
FileName = Helpers.FromUri(request.TextDocument.Uri),
WantsTextChanges = true
};

var omnisharpResponse = await _codeFormatHandler.Handle(omnisharpRequest);
return omnisharpResponse.Changes.Select(change => new TextEdit()
{
NewText = change.NewText,
Range = new Range(new Position(change.StartLine, change.StartColumn), new Position(change.EndLine, change.EndColumn))
}).ToArray();
}
}
}
Loading