Skip to content

Commit aec69bd

Browse files
authored
Merge pull request #195 from Exafunction/formatter
Format the repo using LLVM 18 Clang Formatter
2 parents 9d5a300 + fadf1cd commit aec69bd

25 files changed

+961
-996
lines changed

CodeiumVS/CodeLensConnection/CodeLensConnectionHandler.cs

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,94 +5,97 @@
55

66
namespace CodeiumVS
77
{
8-
using System;
9-
using System.Diagnostics;
10-
using System.IO.Pipes;
11-
using System.Linq;
12-
using System.Threading.Tasks;
8+
using System;
9+
using System.Diagnostics;
10+
using System.IO.Pipes;
11+
using System.Linq;
12+
using System.Threading.Tasks;
1313

14-
using StreamJsonRpc;
14+
using StreamJsonRpc;
1515

16-
using CodeLensConnections = System.Collections.Concurrent.ConcurrentDictionary<System.Guid, CodeLensConnectionHandler>;
17-
using CodeLensDetails = System.Collections.Concurrent.ConcurrentDictionary<System.Guid, FunctionInfo>;
16+
using CodeLensConnections =
17+
System.Collections.Concurrent.ConcurrentDictionary<System.Guid, CodeLensConnectionHandler>;
18+
using CodeLensDetails =
19+
System.Collections.Concurrent.ConcurrentDictionary<System.Guid, FunctionInfo>;
1820

19-
public class CodeLensConnectionHandler : IRemoteVisualStudio, IDisposable
20-
{
21-
private static readonly CodeLensConnections connections = new CodeLensConnections();
22-
private static readonly CodeLensDetails detailsData = new CodeLensDetails();
21+
public class CodeLensConnectionHandler : IRemoteVisualStudio, IDisposable
22+
{
23+
private static readonly CodeLensConnections connections = new CodeLensConnections();
24+
private static readonly CodeLensDetails detailsData = new CodeLensDetails();
2325

24-
private JsonRpc? rpc;
25-
private Guid? dataPointId;
26+
private JsonRpc? rpc;
27+
private Guid? dataPointId;
2628

27-
public static async Task AcceptCodeLensConnections()
29+
public static async Task AcceptCodeLensConnections()
30+
{
31+
try
2832
{
29-
try
30-
{
31-
while (true)
32-
{
33-
var stream = new NamedPipeServerStream(
34-
PipeName.Get(Process.GetCurrentProcess().Id),
35-
PipeDirection.InOut,
36-
NamedPipeServerStream.MaxAllowedServerInstances,
37-
PipeTransmissionMode.Byte,
38-
PipeOptions.Asynchronous);
39-
await stream.WaitForConnectionAsync().Caf();
40-
_ = HandleConnection(stream);
41-
}
42-
}
43-
catch (Exception ex)
33+
while (true)
4434
{
45-
throw;
46-
}
47-
48-
static async Task HandleConnection(NamedPipeServerStream stream)
49-
{
50-
try
51-
{
52-
var handler = new CodeLensConnectionHandler();
53-
var rpc = JsonRpc.Attach(stream, handler);
54-
handler.rpc = rpc;
55-
await rpc.Completion;
56-
handler.Dispose();
57-
stream.Dispose();
58-
}
59-
catch (Exception ex)
60-
{
61-
CodeiumVSPackage.Instance.LogAsync("Handle Connection Error");
62-
}
35+
var stream =
36+
new NamedPipeServerStream(PipeName.Get(Process.GetCurrentProcess().Id),
37+
PipeDirection.InOut,
38+
NamedPipeServerStream.MaxAllowedServerInstances,
39+
PipeTransmissionMode.Byte,
40+
PipeOptions.Asynchronous);
41+
await stream.WaitForConnectionAsync().Caf();
42+
_ = HandleConnection(stream);
6343
}
6444
}
45+
catch (Exception ex)
46+
{
47+
throw;
48+
}
6549

66-
public void Dispose()
50+
static async Task HandleConnection(NamedPipeServerStream stream)
6751
{
68-
if (dataPointId.HasValue)
52+
try
6953
{
70-
_ = connections.TryRemove(dataPointId.Value, out var _);
71-
_ = detailsData.TryRemove(dataPointId.Value, out var _);
54+
var handler = new CodeLensConnectionHandler();
55+
var rpc = JsonRpc.Attach(stream, handler);
56+
handler.rpc = rpc;
57+
await rpc.Completion;
58+
handler.Dispose();
59+
stream.Dispose();
60+
}
61+
catch (Exception ex)
62+
{
63+
CodeiumVSPackage.Instance.LogAsync("Handle Connection Error");
7264
}
7365
}
66+
}
7467

75-
// Called from each CodeLensDataPoint via JSON RPC.
76-
public void RegisterCodeLensDataPoint(Guid id)
68+
public void Dispose()
69+
{
70+
if (dataPointId.HasValue)
7771
{
78-
dataPointId = id;
79-
connections[id] = this;
72+
_ = connections.TryRemove(dataPointId.Value, out var _);
73+
_ = detailsData.TryRemove(dataPointId.Value, out var _);
8074
}
75+
}
8176

82-
public static void StoreDetailsData(Guid id, FunctionInfo closestFunction) => detailsData[id] = closestFunction;
77+
// Called from each CodeLensDataPoint via JSON RPC.
78+
public void RegisterCodeLensDataPoint(Guid id)
79+
{
80+
dataPointId = id;
81+
connections[id] = this;
82+
}
8383

84-
public static FunctionInfo GetDetailsData(Guid id) => detailsData[id];
84+
public static void
85+
StoreDetailsData(Guid id, FunctionInfo closestFunction) => detailsData[id] = closestFunction;
8586

86-
public static async Task RefreshCodeLensDataPoint(Guid id)
87-
{
88-
if (!connections.TryGetValue(id, out var conn))
89-
throw new InvalidOperationException($"CodeLens data point {id} was not registered.");
87+
public static FunctionInfo GetDetailsData(Guid id) => detailsData[id];
9088

91-
Debug.Assert(conn.rpc != null);
92-
await conn.rpc!.InvokeAsync(nameof(IRemoteCodeLens.Refresh)).Caf();
93-
}
89+
public static async Task RefreshCodeLensDataPoint(Guid id)
90+
{
91+
if (!connections.TryGetValue(id, out var conn))
92+
throw new InvalidOperationException($"CodeLens data point {id} was not registered.");
9493

95-
public static async Task RefreshAllCodeLensDataPoints()
96-
=> await Task.WhenAll(connections.Keys.Select(RefreshCodeLensDataPoint)).Caf();
94+
Debug.Assert(conn.rpc != null);
95+
await conn.rpc!.InvokeAsync(nameof(IRemoteCodeLens.Refresh)).Caf();
9796
}
97+
98+
public static async Task RefreshAllCodeLensDataPoints() =>
99+
await Task.WhenAll(connections.Keys.Select(RefreshCodeLensDataPoint)).Caf();
100+
}
98101
}

CodeiumVS/CodeLensConnection/CodeLensListener.cs

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -17,89 +17,87 @@
1717
namespace CodeiumVS
1818
{
1919

20-
[Export(typeof(ICodeLensCallbackListener))]
21-
[ContentType("C/C++")]
22-
[ContentType("CSharp")]
23-
[ContentType("Basic")]
24-
[ContentType("vbscript")]
25-
[ContentType("TypeScript")]
26-
[ContentType("JavaScript")]
27-
[ContentType("html")]
28-
[ContentType("HTMLX")]
29-
[ContentType("Razor")]
30-
public class CodeLensListener : ICodeLensCallbackListener, ICodeLensListener
31-
{
20+
[Export(typeof(ICodeLensCallbackListener))]
21+
[ContentType("C/C++")]
22+
[ContentType("CSharp")]
23+
[ContentType("Basic")]
24+
[ContentType("vbscript")]
25+
[ContentType("TypeScript")]
26+
[ContentType("JavaScript")]
27+
[ContentType("html")]
28+
[ContentType("HTMLX")]
29+
[ContentType("Razor")]
30+
public class CodeLensListener : ICodeLensCallbackListener, ICodeLensListener
31+
{
3232

33-
public int GetVisualStudioPid() => Process.GetCurrentProcess().Id;
33+
public int GetVisualStudioPid() => Process.GetCurrentProcess().Id;
3434

35-
public bool IsCodeiumCodeLensActive() => CodeiumVSPackage.Instance != null && CodeiumVSPackage.Instance.SettingsPage.EnableCodeLens;
36-
FunctionInfo GetClosestFunction(IList<Packets.FunctionInfo>? functions, int line)
35+
public bool
36+
IsCodeiumCodeLensActive() => CodeiumVSPackage.Instance != null
37+
&& CodeiumVSPackage.Instance.SettingsPage.EnableCodeLens;
38+
FunctionInfo GetClosestFunction(IList<Packets.FunctionInfo>? functions, int line)
39+
{
40+
41+
FunctionInfo minFunction = null;
42+
int minDistance = int.MaxValue;
43+
foreach (var f in functions)
3744
{
38-
39-
FunctionInfo minFunction = null;
40-
int minDistance = int.MaxValue;
41-
foreach (var f in functions)
45+
var distance = Math.Abs(f.DefinitionLine - line);
46+
if (distance < minDistance)
4247
{
43-
var distance = Math.Abs(f.DefinitionLine - line);
44-
if (distance < minDistance)
45-
{
46-
minDistance = distance;
47-
minFunction = f;
48-
}
48+
minDistance = distance;
49+
minFunction = f;
4950
}
50-
51-
return minFunction;
5251
}
5352

54-
public async Task<FunctionInfo> LoadInstructions(
55-
Guid dataPointId,
56-
Guid projGuid,
57-
string filePath,
58-
int textStart,
59-
int textLen,
60-
CancellationToken ct)
61-
{
62-
try
63-
{
64-
65-
ITextDocument _document;
66-
TextViewListener.Instance.documentDictionary.TryGetValue(filePath.ToLower(), out _document);
67-
var key = typeof(CodeiumCompletionHandler);
68-
var props = _document.TextBuffer.Properties;
69-
CodeiumCompletionHandler handler;
70-
if (props.ContainsProperty(key))
71-
{
72-
handler = props.GetProperty<CodeiumCompletionHandler>(key);
73-
}
74-
else
75-
{
76-
handler = null;
77-
return null;
78-
}
79-
80-
IList<FunctionInfo>? functions =
81-
await CodeiumVSPackage.Instance.LanguageServer.GetFunctionsAsync(
82-
_document.FilePath,
83-
_document.TextBuffer.CurrentSnapshot.GetText(),
84-
handler.GetLanguage(),
85-
0,
86-
ct);
53+
return minFunction;
54+
}
8755

88-
var line = new Span(textStart, textLen);
89-
var snapshotLine = _document.TextBuffer.CurrentSnapshot.GetLineFromPosition(line.Start);
90-
var lineN = snapshotLine.LineNumber;
91-
FunctionInfo closestFunction = GetClosestFunction(functions, lineN);
92-
CodeLensConnectionHandler.StoreDetailsData(dataPointId, closestFunction);
56+
public async Task<FunctionInfo> LoadInstructions(Guid dataPointId, Guid projGuid,
57+
string filePath, int textStart, int textLen,
58+
CancellationToken ct)
59+
{
60+
try
61+
{
9362

94-
return closestFunction;
63+
ITextDocument _document;
64+
TextViewListener.Instance.documentDictionary.TryGetValue(filePath.ToLower(),
65+
out _document);
66+
var key = typeof(CodeiumCompletionHandler);
67+
var props = _document.TextBuffer.Properties;
68+
CodeiumCompletionHandler handler;
69+
if (props.ContainsProperty(key))
70+
{
71+
handler = props.GetProperty<CodeiumCompletionHandler>(key);
9572
}
96-
catch (Exception ex)
73+
else
9774
{
98-
CodeiumVSPackage.Instance.LogAsync(ex.ToString());
99-
75+
handler = null;
10076
return null;
10177
}
78+
79+
IList<FunctionInfo>? functions =
80+
await CodeiumVSPackage.Instance.LanguageServer.GetFunctionsAsync(
81+
_document.FilePath,
82+
_document.TextBuffer.CurrentSnapshot.GetText(),
83+
handler.GetLanguage(),
84+
0,
85+
ct);
86+
87+
var line = new Span(textStart, textLen);
88+
var snapshotLine = _document.TextBuffer.CurrentSnapshot.GetLineFromPosition(line.Start);
89+
var lineN = snapshotLine.LineNumber;
90+
FunctionInfo closestFunction = GetClosestFunction(functions, lineN);
91+
CodeLensConnectionHandler.StoreDetailsData(dataPointId, closestFunction);
92+
93+
return closestFunction;
10294
}
95+
catch (Exception ex)
96+
{
97+
CodeiumVSPackage.Instance.LogAsync(ex.ToString());
10398

99+
return null;
100+
}
104101
}
105102
}
103+
}

CodeiumVS/CodeiumVS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,4 @@
239239
<Target Name="AfterBuild">
240240
</Target>
241241
-->
242-
</Project>
242+
</Project>

CodeiumVS/CodeiumVSPackage.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ await LogAsync(
7676
{
7777
await LogAsync(
7878
$"CodeiumVSPackage.InitializeAsync: Failed to register commands; Exception {ex}");
79-
await VS.MessageBox.ShowErrorAsync(
80-
"Windsurf: Failed to register commands.",
81-
"Windsurf might not work correctly. Please check the output window for more details.");
79+
await VS.MessageBox.ShowErrorAsync("Windsurf: Failed to register commands.",
80+
"Windsurf might not work correctly. Please check " +
81+
"the output window for more details.");
8282
}
8383

8484
try
@@ -226,9 +226,7 @@ public static void OpenInBrowser(string url)
226226
{
227227
Action<string>[] methods = [
228228
(_url) =>
229-
{
230-
Process.Start(new ProcessStartInfo { FileName = _url, UseShellExecute = true });
231-
},
229+
{ Process.Start(new ProcessStartInfo { FileName = _url, UseShellExecute = true }); },
232230
(_url) =>
233231
{ Process.Start("explorer.exe", _url); },
234232
(_url) =>

0 commit comments

Comments
 (0)