Skip to content

Commit 2e982ff

Browse files
committedMay 5, 2023
Parse function better
1 parent c5a1781 commit 2e982ff

File tree

6 files changed

+55
-40
lines changed

6 files changed

+55
-40
lines changed
 

‎CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
88
## 0.1.0 (Unreleased)
99
> Released N/A
1010
11-
- N/A
11+
- Fix signature help (c5a1781767cefa5281f36c3ba408985e1c52a837)
1212

1313
## 0.0.1
1414
> Released May 03, 2023

‎Server/Buffer.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System.Numerics;
2-
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
1+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
32
using ShaderlabVS;
4-
using static System.Net.Mime.MediaTypeNames;
53

64
namespace ShaderLS
75
{
@@ -20,10 +18,27 @@ public Buffer(string text)
2018
SetWordsInDocuments(text);
2119
}
2220

21+
public string? GetLine(Position position)
22+
{
23+
if (position == null) return default;
24+
string[] lines = _text.Split("\n");
25+
return lines[position.Line];
26+
}
27+
28+
public List<string>? GetLineSplit(Position position)
29+
{
30+
string? line = GetLine(position);
31+
if (line == null) return default;
32+
33+
string front = line.Substring(0, position.Character);
34+
string back = line.Substring(position.Character, line.Length - position.Character);
35+
36+
return new List<string> { front, back };
37+
}
38+
2339
public string GetWordAtPosition(Position position)
2440
{
25-
if (position == null)
26-
return null;
41+
if (position == null) return null;
2742

2843
string[] lines = _text.Split("\n");
2944

@@ -32,7 +47,7 @@ public string GetWordAtPosition(Position position)
3247

3348
string lineStr = lines[line];
3449

35-
string[] words = GetWords(lineStr);
50+
string[] words = Helpers.GetWords(lineStr);
3651

3752
if (words.Length == 0)
3853
return null;
@@ -68,7 +83,7 @@ private void SetWordsInDocuments(string text)
6883
continue;
6984
}
7085

71-
string[] words = GetWords(line);
86+
string[] words = Helpers.GetWords(line);
7287

7388
foreach (var word in words)
7489
{
@@ -78,13 +93,5 @@ private void SetWordsInDocuments(string text)
7893
line = reader.ReadLine();
7994
}
8095
}
81-
82-
private string[] GetWords(string text)
83-
{
84-
return text.Split(
85-
new char[] { '{', '}', ' ', '\t', '(', ')', '[', ']', '+', '-', '*', '/', '%', '^', '>', '<', ':',
86-
'.', ';', '\"', '\'', '?', '\\', '&', '|', '`', '$', '#', ','},
87-
StringSplitOptions.RemoveEmptyEntries);
88-
}
8996
}
9097
}

‎Server/BufferService.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public string GetText(DocumentUri key)
3737
return _buffers[key].GetText();
3838
}
3939

40+
public string? GetLine(DocumentUri key, Position position)
41+
{
42+
return _buffers[key].GetLine(position);
43+
}
44+
45+
public List<string>? GetLineSplit(DocumentUri key, Position position)
46+
{
47+
return _buffers[key].GetLineSplit(position);
48+
}
49+
4050
public string GetWordAtPosition(DocumentUri key, Position position)
4151
{
4252
return _buffers[key].GetWordAtPosition(position);
@@ -47,13 +57,6 @@ public HashSet<string> Tokens(DocumentUri key)
4757
return _buffers[key].Tokens();
4858
}
4959

50-
//public string GetText(DocumentUri key, Position position)
51-
//{
52-
// string text = GetText(key);
53-
// GetIndex(text, position);
54-
// return ;
55-
//}
56-
5760
private static int GetIndex(string buffer, Position position)
5861
{
5962
var index = 0;

‎Server/Handlers/SignatureHelpHandler.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,21 @@ public SignatureHelpHandler(
3434
var uri = request.TextDocument.Uri;
3535
Position position = request.Position;
3636

37-
string current = _workspace.BufferService.GetWordAtPosition(uri, position);
37+
// Attempt to get function name.
38+
List<string>? line = _workspace.BufferService.GetLineSplit(uri, position);
3839

39-
int newChar = Math.Max(position.Character - current.Length, 0);
40-
var newPos = new Position(position.Line, newChar);
40+
if (line == null)
41+
return null;
4142

42-
// Attempt to get function name.
43-
string word = _workspace.BufferService.GetWordAtPosition(uri, newPos);
43+
string[] splits = line[0].Split("(", StringSplitOptions.RemoveEmptyEntries);
44+
45+
if (splits.Length == 0)
46+
return null;
4447

45-
_logger.LogWarning("word: " + word);
48+
int min = Math.Max(splits.Length - 2, 0);
49+
splits = splits[min].Split(new char[] { '.', ' ' });
50+
51+
string word = splits[splits.Length - 1];
4652

4753
var signatures = new List<SignatureInformation>();
4854

@@ -72,8 +78,6 @@ public SignatureHelpHandler(
7278
}
7379
});
7480

75-
var elm = signatures.ElementAt<SignatureInformation>(0);
76-
7781
return new SignatureHelp
7882
{
7983
Signatures = signatures

‎Server/Helpers.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
66
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
77

8-
namespace ShaderLS.LanguageServerProtocol
8+
namespace ShaderLS
99
{
1010
public static class Helpers
1111
{
12+
public static string[] GetWords(string text)
13+
{
14+
return text.Split(
15+
new char[] { '{', '}', ' ', '\t', '(', ')', '[', ']', '+', '-', '*', '/', '%', '^', '>', '<', ':',
16+
'.', ';', '\"', '\'', '?', '\\', '&', '|', '`', '$', '#', ','},
17+
StringSplitOptions.RemoveEmptyEntries);
18+
}
19+
1220
public static DocumentUri ToUri(string fileName) => DocumentUri.File(fileName);
1321
public static string FromUri(DocumentUri uri) => uri.GetFileSystemPath().Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
1422

‎Server/Management/ProjectInfo.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Microsoft.Extensions.Logging;
7-
using OmniSharp.Extensions.LanguageServer.Protocol;
8-
using ShaderLS.LanguageServerProtocol;
1+
using OmniSharp.Extensions.LanguageServer.Protocol;
92

103
namespace ShaderLS.Management
114
{

0 commit comments

Comments
 (0)
Please sign in to comment.