-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf7c040
commit 659a278
Showing
23 changed files
with
963 additions
and
3,776 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
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
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
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
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,41 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Document; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace Yabal.LanguageServer.Handlers; | ||
|
||
public class DefinitionHandler(TextDocumentContainer documentContainer) : IDefinitionHandler | ||
{ | ||
public Task<LocationOrLocationLinks?> Handle(DefinitionParams request, CancellationToken cancellationToken) | ||
{ | ||
if (!documentContainer.Documents.TryGetValue(request.TextDocument.Uri, out var document)) | ||
{ | ||
return Task.FromResult<LocationOrLocationLinks?>(null); | ||
} | ||
|
||
var (_, variable) = document.Builder.Find(request.Position); | ||
|
||
if (variable == null) | ||
{ | ||
return Task.FromResult<LocationOrLocationLinks?>(null); | ||
} | ||
|
||
return Task.FromResult<LocationOrLocationLinks?>(new LocationOrLocationLinks(new LocationOrLocationLink(new Location | ||
{ | ||
Uri = request.TextDocument.Uri, | ||
Range = variable.Identifier.Range.ToRange() | ||
}))); | ||
} | ||
|
||
public DefinitionRegistrationOptions GetRegistrationOptions(DefinitionCapability capability, | ||
ClientCapabilities clientCapabilities) | ||
{ | ||
return new DefinitionRegistrationOptions | ||
{ | ||
DocumentSelector = TextDocumentSelector.ForLanguage("yabal") | ||
}; | ||
} | ||
} |
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
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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OmniSharp.Extensions.LanguageServer.Protocol; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Document; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace Yabal.LanguageServer.Handlers; | ||
|
||
public class RenameHandler(TextDocumentContainer documentContainer) : IRenameHandler | ||
{ | ||
public Task<WorkspaceEdit?> Handle(RenameParams request, CancellationToken cancellationToken) | ||
{ | ||
if (!documentContainer.Documents.TryGetValue(request.TextDocument.Uri, out var document)) | ||
{ | ||
return Task.FromResult<WorkspaceEdit?>(null); | ||
} | ||
|
||
var (_, variable) = document.Builder.Find(request.Position); | ||
|
||
if (variable == null) | ||
{ | ||
return Task.FromResult<WorkspaceEdit?>(null); | ||
} | ||
|
||
return Task.FromResult<WorkspaceEdit?>(new WorkspaceEdit | ||
{ | ||
Changes = new Dictionary<DocumentUri, IEnumerable<TextEdit>> | ||
{ | ||
[request.TextDocument.Uri] = | ||
[ | ||
..variable.References | ||
.OrderByDescending(i => i.Range) | ||
.DistinctBy(i => i.Range.Index) | ||
.Select(i => new TextEdit | ||
{ | ||
Range = i.Range.ToRange(), | ||
NewText = request.NewName | ||
}), | ||
new TextEdit | ||
{ | ||
Range = variable.Identifier.Range.ToRange(), | ||
NewText = request.NewName | ||
} | ||
] | ||
} | ||
}); | ||
} | ||
|
||
public RenameRegistrationOptions GetRegistrationOptions(RenameCapability capability, ClientCapabilities clientCapabilities) | ||
{ | ||
return new RenameRegistrationOptions | ||
{ | ||
DocumentSelector = TextDocumentSelector.ForLanguage("yabal") | ||
}; | ||
} | ||
} |
Oops, something went wrong.