-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up logging. Added range helper. Added hover handler
- Loading branch information
1 parent
379fc46
commit f9af5e2
Showing
4 changed files
with
93 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/OmniSharp.LanguageServerProtocol/Handlers/HoverHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Composition; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.LanguageServer.Capabilities.Client; | ||
using OmniSharp.Extensions.LanguageServer.Models; | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
using OmniSharp.Mef; | ||
using OmniSharp.Models.TypeLookup; | ||
|
||
namespace OmniSharp.LanguageServerProtocol.Handlers | ||
{ | ||
[Shared, Export(typeof(HoverHandler))] | ||
class HoverHandler : IHoverHandler | ||
{ | ||
private HoverCapability _capability; | ||
private readonly IRequestHandler<TypeLookupRequest, TypeLookupResponse> _definitionHandler; | ||
private readonly DocumentSelector _documentSelector; | ||
|
||
[ImportingConstructor] | ||
public HoverHandler(IEnumerable<IRequestHandler> handlers, DocumentSelector documentSelector) | ||
{ | ||
_definitionHandler = handlers.OfType<IRequestHandler<TypeLookupRequest, TypeLookupResponse>>().Single(); | ||
_documentSelector = documentSelector; | ||
} | ||
|
||
public TextDocumentRegistrationOptions GetRegistrationOptions() | ||
{ | ||
return new TextDocumentRegistrationOptions() | ||
{ | ||
DocumentSelector = _documentSelector | ||
}; | ||
} | ||
|
||
public async Task<Hover> Handle(TextDocumentPositionParams request, CancellationToken token) | ||
{ | ||
var omnisharpRequest = new TypeLookupRequest() | ||
{ | ||
FileName = Helpers.FromUri(request.TextDocument.Uri), | ||
Column = Convert.ToInt32(request.Position.Character), | ||
Line = Convert.ToInt32(request.Position.Line), | ||
IncludeDocumentation = true | ||
}; | ||
|
||
var omnisharpResponse = await _definitionHandler.Handle(omnisharpRequest); | ||
|
||
return new Hover() | ||
{ | ||
// TODO: Range? We don't currently have that! | ||
// Range = | ||
Contents = new MarkedStringContainer(omnisharpResponse.Type, omnisharpResponse.Documentation) | ||
}; | ||
} | ||
|
||
public void SetCapability(HoverCapability capability) | ||
{ | ||
_capability = capability; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters