Skip to content

Commit 6d22520

Browse files
committed
Rename
1 parent 0e554e8 commit 6d22520

File tree

4 files changed

+136
-6
lines changed

4 files changed

+136
-6
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using System.Collections.ObjectModel;
2+
using System.Reflection.Metadata;
3+
using System;
4+
using System.Security.Cryptography.Xml;
5+
using Microsoft.Extensions.Logging;
6+
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
7+
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
8+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
9+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
10+
using ShaderlabVS.Data;
11+
using ShaderLS.Management;
12+
13+
namespace ShaderLS.Handlers
14+
{
15+
public class SignatureHelpHandler : SignatureHelpHandlerBase
16+
{
17+
private readonly ILogger<SignatureHelpHandler> _logger;
18+
private readonly ILanguageServerConfiguration _configuration;
19+
private readonly Workspace _workspace;
20+
private readonly DocumentSelector _documentSelector;
21+
22+
public SignatureHelpHandler(
23+
ILogger<SignatureHelpHandler> logger,
24+
ILanguageServerConfiguration configuration,
25+
DocumentSelector documentSelector,
26+
Workspace workspace)
27+
{
28+
this._logger = logger;
29+
this._configuration = configuration;
30+
this._documentSelector = documentSelector;
31+
this._workspace = workspace;
32+
}
33+
34+
public override async Task<SignatureHelp?> Handle(SignatureHelpParams request, CancellationToken cancellationToken)
35+
{
36+
var uri = request.TextDocument.Uri;
37+
Position position = request.Position;
38+
39+
string current = _workspace.BufferService.GetWordAtPosition(uri, position);
40+
41+
int newChar = Math.Max(position.Character - current.Length, 0);
42+
Position newPos = new Position(position.Line, newChar);
43+
44+
// Attempt to get function name.
45+
string word = _workspace.BufferService.GetWordAtPosition(uri, newPos);
46+
47+
_logger.LogWarning("word: " + word);
48+
49+
var signatures = new Container<SignatureInformation>();
50+
51+
ShaderlabDataManager.Instance.HLSLCGFunctions.ForEach(f =>
52+
{
53+
foreach (var item in f.Synopsis)
54+
{
55+
if (f.Name.Equals(word))
56+
{
57+
var sign = CreateSignature(item, f.Description);
58+
signatures.Append(sign);
59+
}
60+
}
61+
});
62+
63+
ShaderlabDataManager.Instance.UnityBuiltinFunctions.ForEach(f =>
64+
{
65+
foreach (var item in f.Synopsis)
66+
{
67+
if (f.Name.Equals(word))
68+
{
69+
var sign = CreateSignature(item, f.Description);
70+
signatures.Append(sign);
71+
}
72+
}
73+
});
74+
75+
return new SignatureHelp
76+
{
77+
Signatures = signatures
78+
};
79+
}
80+
81+
protected override SignatureHelpRegistrationOptions CreateRegistrationOptions(SignatureHelpCapability capability, ClientCapabilities clientCapabilities)
82+
{
83+
return new SignatureHelpRegistrationOptions()
84+
{
85+
DocumentSelector = _documentSelector,
86+
TriggerCharacters = new[] { "(", ",", "<", "{", "[", "," }
87+
};
88+
}
89+
90+
private SignatureInformation CreateSignature(string sign, string documentation)
91+
{
92+
var signature = new SignatureInformation
93+
{
94+
Documentation = documentation,
95+
Label = sign,
96+
Parameters = new()
97+
};
98+
99+
//find the parameters in the method signature (expect methodname(one, two)
100+
string[] pars = sign.Split(new char[] { '(', ',', ')', ';' }, StringSplitOptions.RemoveEmptyEntries);
101+
102+
int locusSearchStart = 0;
103+
for (int i = 1; i < pars.Length; ++i)
104+
{
105+
string param = pars[i].Trim();
106+
107+
if (string.IsNullOrEmpty(param))
108+
continue;
109+
110+
int locusStart = sign.IndexOf(param, locusSearchStart);
111+
112+
if (locusStart >= 0)
113+
{
114+
_logger.LogWarning("param: " + param);
115+
116+
var newPararm = new ParameterInformation()
117+
{
118+
Documentation = "",
119+
Label = param
120+
};
121+
122+
signature.Parameters.Append(newPararm);
123+
}
124+
}
125+
126+
return signature;
127+
}
128+
}
129+
}

Server/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private static void Configure(LanguageServerOptions options)
4343
.WithHandler<CompletionHandler>()
4444
//.WithHandler<CodeActionHandler>()
4545
.WithHandler<HoverHandler>()
46+
.WithHandler<SignatureHelpHandler>()
4647
.WithServices(ConfigureServices);
4748
}
4849

File renamed without changes.

Server/ShaderLS.sln renamed to Server/shader-ls.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.5.33530.505
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ShaderLS", "ShaderLS.csproj", "{FD65A440-C40C-4BCB-A909-82CB77C356F2}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "shader-ls", "shader-ls.csproj", "{43A09270-E39D-465C-B652-FED9BC375593}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{FD65A440-C40C-4BCB-A909-82CB77C356F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{FD65A440-C40C-4BCB-A909-82CB77C356F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{FD65A440-C40C-4BCB-A909-82CB77C356F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{FD65A440-C40C-4BCB-A909-82CB77C356F2}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{43A09270-E39D-465C-B652-FED9BC375593}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{43A09270-E39D-465C-B652-FED9BC375593}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{43A09270-E39D-465C-B652-FED9BC375593}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{43A09270-E39D-465C-B652-FED9BC375593}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
2222
GlobalSection(ExtensibilityGlobals) = postSolution
23-
SolutionGuid = {E33177C7-EFF5-4304-90FA-261BD936E4F4}
23+
SolutionGuid = {68DA2175-5BFE-4CF5-94C1-25124510385B}
2424
EndGlobalSection
2525
EndGlobal

0 commit comments

Comments
 (0)