-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from ezolotko/textdocumentclient-lsp-capabili…
…ties-support Added support for Definition, DocumentHighlights, FoldingRanges to TextDocumentClient.
- Loading branch information
Showing
4 changed files
with
354 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.LanguageServer.Client.Utilities; | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace OmniSharp.Extensions.LanguageServer.Client.Clients | ||
{ | ||
/// <summary> | ||
/// Client for the LSP Text Document API. | ||
/// </summary> | ||
public partial class TextDocumentClient | ||
{ | ||
/// <summary> | ||
/// Request definition at the specified document position. | ||
/// </summary> | ||
/// <param name="filePath"> | ||
/// The full file-system path of the text document. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no definitions are available at the specified position. | ||
/// </returns> | ||
public Task<LocationOrLocationLinks> Definition(string filePath, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
if (string.IsNullOrWhiteSpace(filePath)) | ||
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(filePath)}.", nameof(filePath)); | ||
|
||
var documentUri = DocumentUri.FromFileSystemPath(filePath); | ||
|
||
return Definition(documentUri, line, column, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Request definition at the specified document position. | ||
/// </summary> | ||
/// <param name="documentUri"> | ||
/// The document URI. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no definitions are available at the specified position. | ||
/// </returns> | ||
public Task<LocationOrLocationLinks> Definition(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return PositionalRequest<LocationOrLocationLinks>(DocumentNames.Definition, documentUri, line, column, cancellationToken); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/Client/Clients/TextDocumentClient.DocumentHighlights.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,66 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.LanguageServer.Client.Utilities; | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace OmniSharp.Extensions.LanguageServer.Client.Clients | ||
{ | ||
/// <summary> | ||
/// Client for the LSP Text Document API. | ||
/// </summary> | ||
public partial class TextDocumentClient | ||
{ | ||
/// <summary> | ||
/// Request document highlights at the specified document position. | ||
/// </summary> | ||
/// <param name="filePath"> | ||
/// The full file-system path of the text document. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no document highlights are available at the specified position. | ||
/// </returns> | ||
public Task<DocumentHighlightContainer> DocumentHighlights(string filePath, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
if (string.IsNullOrWhiteSpace(filePath)) | ||
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(filePath)}.", nameof(filePath)); | ||
|
||
var documentUri = DocumentUri.FromFileSystemPath(filePath); | ||
|
||
return DocumentHighlights(documentUri, line, column, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Request document highlights at the specified document position. | ||
/// </summary> | ||
/// <param name="documentUri"> | ||
/// The document URI. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no document highlights are available at the specified position. | ||
/// </returns> | ||
public Task<DocumentHighlightContainer> DocumentHighlights(Uri documentUri, int line, int column, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return PositionalRequest<DocumentHighlightContainer>(DocumentNames.DocumentHighlight, documentUri, line, column, cancellationToken); | ||
} | ||
} | ||
} |
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,66 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.LanguageServer.Client.Utilities; | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace OmniSharp.Extensions.LanguageServer.Client.Clients | ||
{ | ||
/// <summary> | ||
/// Client for the LSP Text Document API. | ||
/// </summary> | ||
public partial class TextDocumentClient | ||
{ | ||
/// <summary> | ||
/// Request document folding ranges. | ||
/// </summary> | ||
/// <param name="filePath"> | ||
/// The full file-system path of the text document. | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no document highlights are available at the specified position. | ||
/// </returns> | ||
public Task<Container<FoldingRange>> FoldingRanges(string filePath, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
if (string.IsNullOrWhiteSpace(filePath)) | ||
throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(filePath)}.", nameof(filePath)); | ||
|
||
var documentUri = DocumentUri.FromFileSystemPath(filePath); | ||
|
||
return FoldingRanges(documentUri, cancellationToken); | ||
} | ||
|
||
/// <summary> | ||
/// Request document highlights at the specified document position. | ||
/// </summary> | ||
/// <param name="documentUri"> | ||
/// The document URI. | ||
/// </param> | ||
/// <param name="line"> | ||
/// The target line (0-based). | ||
/// </param> | ||
/// <param name="column"> | ||
/// The target column (0-based). | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// An optional <see cref="CancellationToken"/> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// A <see cref="Task{TResult}"/> that resolves to the completions or <c>null</c> if no document highlights are available at the specified position. | ||
/// </returns> | ||
public async Task<Container<FoldingRange>> FoldingRanges(Uri documentUri, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
var request = new FoldingRangeRequestParam { | ||
TextDocument = new TextDocumentItem { | ||
Uri = documentUri | ||
} | ||
}; | ||
|
||
return await Client.SendRequest<Container<FoldingRange>>(DocumentNames.FoldingRange, request, cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} |
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