Skip to content

Commit e7c662a

Browse files
committed
Pass workspace
1 parent b0c869f commit e7c662a

19 files changed

+411
-181
lines changed

Handlers/CompletionHandler.cs

Lines changed: 0 additions & 98 deletions
This file was deleted.

Management/Workspace.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.

Server/Buffer.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using ShaderlabVS;
2+
3+
namespace ShaderLS
4+
{
5+
public class Buffer
6+
{
7+
private string _text = "";
8+
private HashSet<string> _tokens = new();
9+
10+
public string GetText() { return _text; }
11+
public HashSet<string> Tokens() { return _tokens; }
12+
13+
public Buffer(string text)
14+
{
15+
this._text = text;
16+
SetWordsInDocuments(text);
17+
}
18+
19+
private void SetWordsInDocuments(string text)
20+
{
21+
var reader = new StringReader(text);
22+
23+
string line = reader.ReadLine();
24+
25+
while (line != null)
26+
{
27+
if (Utilities.IsCommentLine(line))
28+
{
29+
line = reader.ReadLine();
30+
continue;
31+
}
32+
33+
string[] words = line.Split(
34+
new char[] { '{', '}', ' ', '\t', '(', ')', '[', ']', '+', '-', '*', '/', '%', '^', '>', '<', ':',
35+
'.', ';', '\"', '\'', '?', '\\', '&', '|', '`', '$', '#', ','},
36+
StringSplitOptions.RemoveEmptyEntries);
37+
38+
foreach (var word in words)
39+
{
40+
_tokens.Add(word);
41+
}
42+
43+
line = reader.ReadLine();
44+
}
45+
}
46+
}
47+
}

BufferService.cs renamed to Server/BufferService.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,45 @@ namespace ShaderLS
77
{
88
public class BufferService
99
{
10-
private readonly ConcurrentDictionary<DocumentUri, string> buffers = new();
10+
private readonly ConcurrentDictionary<DocumentUri, Buffer> _buffers = new();
1111

1212
public void Add(DocumentUri key, string text)
1313
{
14-
buffers.TryAdd(key, text);
14+
_buffers.TryAdd(key, new Buffer(text));
1515
}
1616

1717
public void Remove(DocumentUri key)
1818
{
19-
buffers.TryRemove(key, out _);
19+
_buffers.TryRemove(key, out _);
2020
}
2121

22-
public string GetText(DocumentUri key)
22+
public void ApplyFullChange(DocumentUri key, string text)
2323
{
24-
return buffers[key];
24+
var buffer = _buffers[key];
25+
_buffers.TryUpdate(key, new Buffer(text), buffer);
2526
}
2627

27-
public void ApplyFullChange(DocumentUri key, string text)
28+
public void ApplyIncrementalChange(DocumentUri key, Range range, string text)
2829
{
29-
var buffer = buffers[key];
30-
buffers.TryUpdate(key, text, buffer);
30+
var buffer = _buffers[key];
31+
var newText = Splice(buffer.GetText(), range, text);
32+
_buffers.TryUpdate(key, new Buffer(newText), buffer);
3133
}
3234

33-
public void ApplyIncrementalChange(DocumentUri key, Range range, string text)
35+
public string GetText(DocumentUri key)
36+
{
37+
return _buffers[key].GetText();
38+
}
39+
40+
public HashSet<string> Tokens(DocumentUri key)
3441
{
35-
var buffer = buffers[key];
36-
var newText = Splice(buffer, range, text);
37-
buffers.TryUpdate(key, newText, buffer);
42+
return _buffers[key].Tokens();
3843
}
3944

4045
private static int GetIndex(string buffer, Position position)
4146
{
4247
var index = 0;
43-
for (var i = 0; i < position.Line; i++)
48+
for (var i = 0; i < position.Line; ++i)
4449
{
4550
index = buffer.IndexOf('\n', index) + 1;
4651
}
File renamed without changes.

0 commit comments

Comments
 (0)