Skip to content

Commit d6c35fa

Browse files
committed
apply code style
1 parent ba5efa4 commit d6c35fa

File tree

63 files changed

+649
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+649
-125
lines changed

.github/workflows/code-quality.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ jobs:
2828
- name: Restore dependencies
2929
run: dotnet restore
3030

31-
- name: Run dotnet format
32-
run: dotnet format --verify-no-changes --verbosity diagnostic
31+
# Disabled: Project uses Rider formatting which may differ from dotnet format
32+
# - name: Run dotnet format
33+
# run: dotnet format --verify-no-changes --verbosity diagnostic
3334

3435
- name: Run dotnet build analyzers
35-
run: dotnet build --configuration Release /p:TreatWarningsAsErrors=true
36+
run: dotnet build --configuration Release /p:TreatWarningsAsErrors=false
37+
38+
- name: Run Roslyn analyzers
39+
run: dotnet build --configuration Release /p:RunAnalyzers=true /p:AnalysisLevel=latest
3640

3741
dependency-review:
3842
name: Dependency Review

CONTRIBUTING.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ LanguageServer.Framework/
106106

107107
### Code Style
108108

109+
**This project uses JetBrains Rider for code formatting.** See [CODE_FORMATTING.md](CODE_FORMATTING.md) for detailed formatting guidelines.
110+
109111
```csharp
110112
// ✅ Good
111113
/// <summary>
@@ -127,6 +129,8 @@ public class hoverhandler { // Bad naming, no docs
127129
}
128130
```
129131

132+
**Note**: CI format checking is disabled to allow Rider formatting. Format your code with Rider (`Ctrl+Alt+L`) before committing.
133+
130134
### Naming Conventions
131135

132136
- **Classes**: PascalCase (e.g., `LanguageServer`, `HoverHandler`)
@@ -213,11 +217,18 @@ public async Task HoverHandler_ShouldReturnHoverInformation()
213217
- Follow the coding standards
214218
- Add tests for new functionality
215219
- Update documentation as needed
220+
- **Format code with Rider** (`Ctrl+Alt+L` / `Cmd+Option+L`)
216221

217222
4. **Test your changes:**
218223
```bash
219-
dotnet build
220-
dotnet test
224+
# Build the project
225+
dotnet build --configuration Release
226+
227+
# Run all tests
228+
dotnet test --configuration Release
229+
230+
# Optional: Check formatting (may differ from Rider)
231+
dotnet format --verify-no-changes
221232
```
222233

223234
5. **Commit your changes:**
Lines changed: 189 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,191 @@
1-
[*.cs]
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# All files
7+
[*]
8+
charset = utf-8
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
# Code files
13+
[*.{cs,csx,vb,vbx}]
214
indent_size = 4
315
indent_style = space
4-
trim_trailing_whitespace = true
5-
insert_final_newline = true
16+
tab_width = 4
17+
18+
# C# files
19+
[*.cs]
20+
21+
# New line preferences
22+
csharp_new_line_before_open_brace = all
23+
csharp_new_line_before_else = true
24+
csharp_new_line_before_catch = true
25+
csharp_new_line_before_finally = true
26+
csharp_new_line_before_members_in_object_initializers = true
27+
csharp_new_line_before_members_in_anonymous_types = true
28+
csharp_new_line_between_query_expression_clauses = true
29+
30+
# Indentation preferences
31+
csharp_indent_case_contents = true
32+
csharp_indent_switch_labels = true
33+
csharp_indent_labels = one_less_than_current
34+
csharp_indent_block_contents = true
35+
csharp_indent_braces = false
36+
csharp_indent_case_contents_when_block = false
37+
38+
# Space preferences
39+
csharp_space_after_cast = false
40+
csharp_space_after_keywords_in_control_flow_statements = true
41+
csharp_space_between_parentheses = false
42+
csharp_space_before_colon_in_inheritance_clause = true
43+
csharp_space_after_colon_in_inheritance_clause = true
44+
csharp_space_around_binary_operators = before_and_after
45+
csharp_space_between_method_declaration_parameter_list_parentheses = false
46+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
47+
csharp_space_between_method_call_name_and_opening_parenthesis = false
48+
csharp_space_between_method_call_parameter_list_parentheses = false
49+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
50+
csharp_space_after_comma = true
51+
csharp_space_after_dot = false
52+
53+
# Organize usings
54+
dotnet_sort_system_directives_first = true
55+
dotnet_separate_import_directive_groups = false
56+
57+
# Code style rules
58+
[*.{cs,vb}]
59+
dotnet_style_qualification_for_field = false:silent
60+
dotnet_style_qualification_for_property = false:silent
61+
dotnet_style_qualification_for_method = false:silent
62+
dotnet_style_qualification_for_event = false:silent
63+
64+
# Language keywords vs BCL types preferences
65+
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
66+
dotnet_style_predefined_type_for_member_access = true:silent
67+
68+
# Modifier preferences
69+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
70+
dotnet_style_readonly_field = true:suggestion
71+
csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:suggestion
72+
73+
# Expression-level preferences
74+
dotnet_style_object_initializer = true:suggestion
75+
dotnet_style_collection_initializer = true:suggestion
76+
dotnet_style_explicit_tuple_names = true:suggestion
77+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
78+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
79+
dotnet_style_prefer_auto_properties = true:suggestion
80+
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
81+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
82+
dotnet_style_prefer_compound_assignment = true:suggestion
83+
84+
# Modern .NET preferences
85+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
86+
dotnet_style_prefer_simplified_interpolation = true:suggestion
87+
dotnet_style_namespace_match_folder = true:suggestion
88+
dotnet_style_allow_multiple_blank_lines_experimental = false:silent
89+
dotnet_style_allow_statement_immediately_after_block_experimental = false:silent
90+
91+
# C# Code Style Rules
92+
[*.cs]
93+
# var preferences - Use var everywhere (modern C# style)
94+
csharp_style_var_for_built_in_types = true:suggestion
95+
csharp_style_var_when_type_is_apparent = true:suggestion
96+
csharp_style_var_elsewhere = true:suggestion
97+
98+
# Expression-bodied members
99+
csharp_style_expression_bodied_methods = false:silent
100+
csharp_style_expression_bodied_constructors = false:silent
101+
csharp_style_expression_bodied_operators = false:silent
102+
csharp_style_expression_bodied_properties = true:silent
103+
csharp_style_expression_bodied_indexers = true:silent
104+
csharp_style_expression_bodied_accessors = true:silent
105+
csharp_style_expression_bodied_lambdas = true:silent
106+
csharp_style_expression_bodied_local_functions = false:silent
107+
108+
# Pattern matching preferences
109+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
110+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
111+
csharp_style_prefer_switch_expression = true:suggestion
112+
csharp_style_prefer_pattern_matching = true:silent
113+
csharp_style_prefer_not_pattern = true:suggestion
114+
115+
# Null-checking preferences
116+
csharp_style_throw_expression = true:suggestion
117+
csharp_style_prefer_null_check_over_type_check = true:suggestion
118+
csharp_style_conditional_delegate_call = true:suggestion
119+
120+
# Code block preferences
121+
csharp_prefer_braces = true:silent
122+
csharp_prefer_simple_using_statement = true:suggestion
123+
csharp_prefer_static_local_function = true:suggestion
124+
125+
# 'using' directive preferences
126+
csharp_using_directive_placement = outside_namespace:suggestion
127+
128+
#### Modern C# Features (C# 9.0+) ####
129+
130+
# C# 9.0 - Target-typed new expressions
131+
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
132+
133+
# C# 9.0 - Prefer index operator
134+
csharp_style_prefer_index_operator = true:suggestion
135+
csharp_style_prefer_range_operator = true:suggestion
136+
137+
# C# 10.0 - Namespace preferences
138+
csharp_style_namespace_declarations = file_scoped:suggestion
139+
140+
# C# 11.0 - Prefer tuple swap
141+
csharp_style_prefer_tuple_swap = true:suggestion
142+
143+
# C# 12.0 - Primary constructors
144+
csharp_style_prefer_primary_constructors = true:suggestion
145+
146+
# Modern null checking (C# 8.0+)
147+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
148+
dotnet_style_coalesce_expression = true:suggestion
149+
dotnet_style_null_propagation = true:suggestion
150+
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
151+
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
152+
153+
# C# 9.0+ - Discard preferences
154+
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
155+
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
156+
157+
# C# 8.0+ - Inline variable declaration
158+
csharp_style_inlined_variable_declaration = true:suggestion
159+
160+
# C# 7.0+ - Prefer local over anonymous function
161+
csharp_style_pattern_local_over_anonymous_function = true:suggestion
162+
163+
# C# 9.0+ - Extended property patterns
164+
csharp_style_prefer_extended_property_pattern = true:suggestion
165+
166+
# Modern parameter preferences
167+
dotnet_code_quality_unused_parameters = all:suggestion
168+
169+
# Modern simplification preferences
170+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
171+
dotnet_style_prefer_simplified_interpolation = true:suggestion
172+
173+
# C# 10.0+ - Constant pattern preferences
174+
csharp_style_prefer_top_level_statements = false:silent
175+
176+
# Collection initialization
177+
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
178+
179+
# Method group conversion
180+
csharp_style_prefer_method_group_conversion = true:silent
181+
182+
# Expression preferences for modern C#
183+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
184+
csharp_style_prefer_readonly_struct = true:suggestion
185+
csharp_style_prefer_readonly_struct_member = true:suggestion
186+
187+
# File header (optional - uncomment if needed)
188+
# file_header_template = Copyright (c) CppCXY. All rights reserved.
189+
190+
# Naming Conventions are handled by Rider/.DotSettings
191+
# We keep them relaxed here to avoid conflicts

LanguageServer.Framework/LSPCommunicationBase.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public abstract class LSPCommunicationBase : IDisposable
1919
{
2020
public JsonSerializerOptions JsonSerializerOptions { get; } = new()
2121
{
22-
TypeInfoResolver = JsonProtocolContext.Default,
23-
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
22+
TypeInfoResolver = JsonProtocolContext.Default, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
2423
};
2524

2625
protected JsonProtocolReader Reader { get; }
@@ -157,7 +156,8 @@ private async Task OnDispatch(Message message)
157156
{
158157
case RequestMessage request:
159158
{
160-
if (RequestHandlers.TryGetValue(request.Method, out var handler))
159+
if (RequestHandlers.TryGetValue(request.Method,
160+
out var handler))
161161
{
162162
MetricsCollector?.RecordRequestStart(request.Method);
163163
var startTime = DateTime.UtcNow;
@@ -223,7 +223,8 @@ private async Task OnDispatch(Message message)
223223
}
224224
case NotificationMessage notification:
225225
{
226-
if (NotificationHandlers.TryGetValue(notification.Method, out var handler))
226+
if (NotificationHandlers.TryGetValue(notification.Method,
227+
out var handler))
227228
{
228229
MetricsCollector?.RecordNotification(notification.Method);
229230

@@ -265,7 +266,9 @@ public Task Run()
265266
try
266267
{
267268
if (ExitTokenSource is not null)
269+
{
268270
throw new InvalidOperationException("Already running.");
271+
}
269272

270273
ExitTokenSource = new CancellationTokenSource();
271274

@@ -278,7 +281,10 @@ public Task Run()
278281
var message = await Reader.ReadAsync(ExitTokenSource.Token);
279282
MetricsCollector?.RecordMessageReceived();
280283

281-
if (BaseHandle(message)) continue;
284+
if (BaseHandle(message))
285+
{
286+
continue;
287+
}
282288

283289
Scheduler.Schedule(OnDispatch, message);
284290
}
@@ -312,7 +318,10 @@ public void Exit()
312318
try
313319
{
314320
if (ExitTokenSource is null)
321+
{
315322
throw new InvalidOperationException("Run() must be called before exit");
323+
}
324+
316325
ExitTokenSource.Cancel();
317326
}
318327
finally
@@ -323,7 +332,10 @@ public void Exit()
323332

324333
protected virtual void Dispose(bool disposing)
325334
{
326-
if (_disposed) return;
335+
if (_disposed)
336+
{
337+
return;
338+
}
327339

328340
if (disposing)
329341
{
@@ -341,9 +353,15 @@ protected virtual void Dispose(bool disposing)
341353
ExitTokenSource?.Dispose();
342354
_exitTokenLock.Dispose();
343355

344-
if (Scheduler is IDisposable disposableScheduler) disposableScheduler.Dispose();
356+
if (Scheduler is IDisposable disposableScheduler)
357+
{
358+
disposableScheduler.Dispose();
359+
}
345360

346-
if (Writer is IDisposable disposableWriter) disposableWriter.Dispose();
361+
if (Writer is IDisposable disposableWriter)
362+
{
363+
disposableWriter.Dispose();
364+
}
347365
}
348366

349367
_disposed = true;

LanguageServer.Framework/Protocol/Capabilities/Server/Union/TextDocumentSyncOptionsOrKind.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,27 @@ public override TextDocumentSyncOptionsOrKind Read(ref Utf8JsonReader reader, Ty
4040
JsonSerializerOptions options)
4141
{
4242
if (reader.TokenType == JsonTokenType.StartObject)
43+
{
4344
return new TextDocumentSyncOptionsOrKind(
4445
JsonSerializer.Deserialize<TextDocumentSyncOptions>(ref reader, options)!);
46+
}
4547
else
48+
{
4649
return new TextDocumentSyncOptionsOrKind(
4750
JsonSerializer.Deserialize<TextDocumentSyncKind>(ref reader, options)!);
51+
}
4852
}
4953

5054
public override void Write(Utf8JsonWriter writer, TextDocumentSyncOptionsOrKind value,
5155
JsonSerializerOptions options)
5256
{
5357
if (value.Value != null)
58+
{
5459
JsonSerializer.Serialize(writer, value.Value, options);
60+
}
5561
else
62+
{
5663
JsonSerializer.Serialize(writer, value.KindValue, options);
64+
}
5765
}
5866
}

0 commit comments

Comments
 (0)