Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit e1a43f3

Browse files
authored
Enable C# nullable reference types in LanguageServer project (#645)
* Enable nullable in LanguageServer.csproj * Update nullables in Communication.cs * Update nullables in EditorState.cs and ProjectLoader.cs * Update nullables in FileSystemWatcher.cs * Use SelectNotNull in FileSystemWatcher.cs * Update nullables in LanguageServer.cs and Utils.cs * Update nullables in Program.cs * Fix remaining nullable errors * Avoid extra null check * Add LanguageServer to InternalsVisibleTo * Fix signing
1 parent 6602eed commit e1a43f3

File tree

16 files changed

+167
-160
lines changed

16 files changed

+167
-160
lines changed

src/Common/DelaySign.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
#if SIGNED
45
using System.Reflection;
56

67
// Attributes for delay-signing
7-
#if SIGNED
8-
[assembly:AssemblyKeyFile("..\\..\\..\\build\\267DevDivSNKey2048.snk")]
9-
[assembly:AssemblyDelaySign(true)]
10-
#endif
11-
12-
internal static class SigningConstants
13-
{
14-
#if SIGNED
15-
public const string PublicKey = ", PublicKey=" +
16-
"002400000c800000140100000602000000240000525341310008000001000100613399aff18ef1" +
17-
"a2c2514a273a42d9042b72321f1757102df9ebada69923e2738406c21e5b801552ab8d200a65a2" +
18-
"35e001ac9adc25f2d811eb09496a4c6a59d4619589c69f5baf0c4179a47311d92555cd006acc8b" +
19-
"5959f2bd6e10e360c34537a1d266da8085856583c85d81da7f3ec01ed9564c58d93d713cd0172c" +
20-
"8e23a10f0239b80c96b07736f5d8b022542a4e74251a5f432824318b3539a5a087f8e53d2f135f" +
21-
"9ca47f3bb2e10aff0af0849504fb7cea3ff192dc8de0edad64c68efde34c56d302ad55fd6e80f3" +
22-
"02d5efcdeae953658d3452561b5f36c542efdbdd9f888538d374cef106acf7d93a4445c3c73cd9" +
23-
"11f0571aaf3d54da12b11ddec375b3";
24-
#else
25-
public const string PublicKey = "";
8+
[assembly: AssemblyKeyFile("..\\..\\..\\build\\267DevDivSNKey2048.snk")]
9+
[assembly: AssemblyDelaySign(true)]
2610
#endif
27-
}

src/Common/SigningConstants.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
internal static class SigningConstants
5+
{
6+
#if SIGNED
7+
public const string PublicKey = ", PublicKey=" +
8+
"002400000c800000140100000602000000240000525341310008000001000100613399aff18ef1" +
9+
"a2c2514a273a42d9042b72321f1757102df9ebada69923e2738406c21e5b801552ab8d200a65a2" +
10+
"35e001ac9adc25f2d811eb09496a4c6a59d4619589c69f5baf0c4179a47311d92555cd006acc8b" +
11+
"5959f2bd6e10e360c34537a1d266da8085856583c85d81da7f3ec01ed9564c58d93d713cd0172c" +
12+
"8e23a10f0239b80c96b07736f5d8b022542a4e74251a5f432824318b3539a5a087f8e53d2f135f" +
13+
"9ca47f3bb2e10aff0af0849504fb7cea3ff192dc8de0edad64c68efde34c56d302ad55fd6e80f3" +
14+
"02d5efcdeae953658d3452561b5f36c542efdbdd9f888538d374cef106acf7d93a4445c3c73cd9" +
15+
"11f0571aaf3d54da12b11ddec375b3";
16+
#else
17+
public const string PublicKey = "";
18+
#endif
19+
}

src/QsCompiler/CompilationManager/ProjectManager.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Concurrent;
66
using System.Collections.Generic;
77
using System.Collections.Immutable;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.IO;
910
using System.Linq;
1011
using System.Reflection;
@@ -45,7 +46,7 @@ public ProjectProperties(
4546

4647
public class ProjectInformation
4748
{
48-
public delegate bool Loader(Uri projectFile, out ProjectInformation projectInfo);
49+
public delegate bool Loader(Uri projectFile, [NotNullWhen(true)] out ProjectInformation? projectInfo);
4950

5051
internal readonly ProjectProperties Properties;
5152
public readonly ImmutableArray<string> SourceFiles;
@@ -904,10 +905,9 @@ public Task ProjectChangedOnDiskAsync(
904905
// TODO: allow to cancel this task via cancellation token?
905906
return this.load.QueueForExecutionAsync(() =>
906907
{
907-
var loaded = projectLoader(projectFile, out ProjectInformation info);
908908
var existing = this.projects.TryRemove(projectFile, out Project current) ? current : null;
909909

910-
if (!loaded)
910+
if (!projectLoader(projectFile, out var info))
911911
{
912912
existing?.LoadProjectAsync(
913913
ImmutableDictionary<Uri, Uri?>.Empty,
@@ -986,7 +986,7 @@ public Task AssemblyChangedOnDiskAsync(Uri dllPath)
986986
/// if the modified file is a source file of that project and not open in the editor
987987
/// (i.e. openInEditor is null or returns null for that file) at the time of execution.
988988
/// </summary>
989-
public Task SourceFileChangedOnDiskAsync(Uri sourceFile, Func<Uri, FileContentManager>? openInEditor = null)
989+
public Task SourceFileChangedOnDiskAsync(Uri sourceFile, Func<Uri, FileContentManager?>? openInEditor = null)
990990
{
991991
if (sourceFile == null)
992992
{
@@ -1061,7 +1061,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
10611061
/// or if the specified position is not a valid position within the file,
10621062
/// or if a file affected by the rename operation belongs to several compilation units.
10631063
/// </summary>
1064-
public WorkspaceEdit? Rename(RenameParams param, bool versionedChanges) // versionedChanges is unused (WorkspaceEdit contains both Changes and DocumentChanges, but the version nr is null)
1064+
public WorkspaceEdit? Rename(RenameParams? param, bool versionedChanges) // versionedChanges is unused (WorkspaceEdit contains both Changes and DocumentChanges, but the version nr is null)
10651065
{
10661066
if (param?.TextDocument?.Uri == null)
10671067
{
@@ -1111,7 +1111,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11111111
/// Fails silently without logging anything if an exception occurs upon evaluating the query
11121112
/// (occasional failures are to be expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11131113
/// </summary>
1114-
public Location? DefinitionLocation(TextDocumentPositionParams param) =>
1114+
public Location? DefinitionLocation(TextDocumentPositionParams? param) =>
11151115
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
11161116
param?.TextDocument, (file, c) => file.DefinitionLocation(c, param?.Position?.ToQSharp()), suppressExceptionLogging: true);
11171117

@@ -1125,7 +1125,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11251125
/// Fails silently without logging anything if an exception occurs upon evaluating the query
11261126
/// (occasional failures are to be expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11271127
/// </summary>
1128-
public SignatureHelp? SignatureHelp(TextDocumentPositionParams param, MarkupKind format = MarkupKind.PlainText) =>
1128+
public SignatureHelp? SignatureHelp(TextDocumentPositionParams? param, MarkupKind format = MarkupKind.PlainText) =>
11291129
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
11301130
param?.TextDocument, (file, c) => file.SignatureHelp(c, param?.Position?.ToQSharp(), format), suppressExceptionLogging: true);
11311131

@@ -1138,7 +1138,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11381138
/// Fails silently without logging anything if an exception occurs upon evaluating the query
11391139
/// (occasional failures are to be expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11401140
/// </summary>
1141-
public Hover? HoverInformation(TextDocumentPositionParams param, MarkupKind format = MarkupKind.PlainText) =>
1141+
public Hover? HoverInformation(TextDocumentPositionParams? param, MarkupKind format = MarkupKind.PlainText) =>
11421142
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
11431143
param?.TextDocument, (file, c) => file.HoverInformation(c, param?.Position?.ToQSharp(), format), suppressExceptionLogging: true);
11441144

@@ -1151,7 +1151,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11511151
/// Fails silently without logging anything if an exception occurs upon evaluating the query
11521152
/// (occasional failures are to be expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11531153
/// </summary>
1154-
public DocumentHighlight[]? DocumentHighlights(TextDocumentPositionParams param) =>
1154+
public DocumentHighlight[]? DocumentHighlights(TextDocumentPositionParams? param) =>
11551155
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
11561156
param?.TextDocument, (file, c) => file.DocumentHighlights(c, param?.Position?.ToQSharp()), suppressExceptionLogging: true);
11571157

@@ -1164,7 +1164,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11641164
/// Fails silently without logging anything if an exception occurs upon evaluating the query
11651165
/// (occasional failures are to be expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11661166
/// </summary>
1167-
public Location[]? SymbolReferences(ReferenceParams param) =>
1167+
public Location[]? SymbolReferences(ReferenceParams? param) =>
11681168
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
11691169
param?.TextDocument, (file, c) => file.SymbolReferences(c, param?.Position?.ToQSharp(), param?.Context), suppressExceptionLogging: true);
11701170

@@ -1175,7 +1175,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11751175
/// Fails silently without logging anything if an exception occurs upon evaluating the query
11761176
/// (occasional failures are to be expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11771177
/// </summary>
1178-
public SymbolInformation[]? DocumentSymbols(DocumentSymbolParams param) =>
1178+
public SymbolInformation[]? DocumentSymbols(DocumentSymbolParams? param) =>
11791179
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
11801180
param?.TextDocument, (file, _) => file.DocumentSymbols(), suppressExceptionLogging: true);
11811181

@@ -1186,7 +1186,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11861186
/// Fails silently without logging anything if an exception occurs upon evaluating the query
11871187
/// (occasional failures are to be expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11881188
/// </summary>
1189-
public ILookup<string, WorkspaceEdit>? CodeActions(CodeActionParams param) =>
1189+
public ILookup<string, WorkspaceEdit>? CodeActions(CodeActionParams? param) =>
11901190
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
11911191
param?.TextDocument, (file, c) => file.CodeActions(c, param?.Range?.ToQSharp(), param?.Context), suppressExceptionLogging: true);
11921192

@@ -1197,7 +1197,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
11971197
/// without logging anything if an exception occurs upon evaluating the query (occasional failures are to be
11981198
/// expected as the evaluation is a readonly query running in parallel to the ongoing processing).
11991199
/// </summary>
1200-
public CompletionList? Completions(TextDocumentPositionParams param) =>
1200+
public CompletionList? Completions(TextDocumentPositionParams? param) =>
12011201
this.Manager(param?.TextDocument?.Uri)?.FileQuery(
12021202
param?.TextDocument,
12031203
(file, compilation) => file.Completions(compilation, param?.Position?.ToQSharp()),
@@ -1213,7 +1213,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
12131213
/// failures are to be expected as the evaluation is a read-only query running in parallel to the ongoing
12141214
/// processing).
12151215
/// </summary>
1216-
public CompletionItem? ResolveCompletion(CompletionItem item, CompletionItemData data, MarkupKind format) =>
1216+
public CompletionItem? ResolveCompletion(CompletionItem item, CompletionItemData? data, MarkupKind format) =>
12171217
this.Manager(data?.TextDocument?.Uri)?.FileQuery(
12181218
data?.TextDocument,
12191219
(_, compilation) => compilation.ResolveCompletion(item, data, format),
@@ -1256,7 +1256,7 @@ public Task ManagerTaskAsync(Uri file, Action<CompilationUnitManager, bool> exec
12561256
/// Note: this method waits for all currently running or queued tasks to finish
12571257
/// before accumulating the diagnostics by calling FlushAndExecute.
12581258
/// </summary>
1259-
public PublishDiagnosticParams[]? GetDiagnostics(Uri file)
1259+
public PublishDiagnosticParams[]? GetDiagnostics(Uri? file)
12601260
{
12611261
this.load.QueueForExecution(
12621262
() =>

src/QsCompiler/DocumentationParser/DocumentationParser.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
<ItemGroup>
2424
<Compile Include="..\..\Common\DelaySign.cs" Link="Properties\DelaySign.cs" />
25+
<Compile Include="..\..\Common\SigningConstants.cs" Link="Properties\SigningConstants.cs" />
2526
</ItemGroup>
2627

2728
<ItemGroup>

src/QsCompiler/LanguageServer/Communication.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public static class Codes
3030
}
3131

3232
public readonly int Code;
33-
public readonly string Message;
33+
public readonly string? Message;
3434

35-
public ProtocolError(int code, string message = null)
35+
public ProtocolError(int code, string? message = null)
3636
{
3737
this.Code = code;
3838
this.Message = message;
@@ -56,20 +56,20 @@ public static class Workarounds
5656
public class CodeActionParams
5757
{
5858
[DataMember(Name = "textDocument")]
59-
public TextDocumentIdentifier TextDocument { get; set; }
59+
public TextDocumentIdentifier? TextDocument { get; set; }
6060

6161
[DataMember(Name = "range")]
62-
public VisualStudio.LanguageServer.Protocol.Range Range { get; set; }
62+
public VisualStudio.LanguageServer.Protocol.Range? Range { get; set; }
6363

6464
[DataMember(Name = "context")]
65-
public CodeActionContext Context { get; set; }
65+
public CodeActionContext? Context { get; set; }
6666

6767
public VisualStudio.LanguageServer.Protocol.CodeActionParams ToCodeActionParams() =>
6868
new VisualStudio.LanguageServer.Protocol.CodeActionParams
6969
{
7070
TextDocument = this.TextDocument,
7171
Range = this.Range,
72-
Context = this.Context.ToCodeActionContext()
72+
Context = this.Context?.ToCodeActionContext()
7373
};
7474
}
7575

@@ -82,7 +82,7 @@ public VisualStudio.LanguageServer.Protocol.CodeActionParams ToCodeActionParams(
8282
public class CodeActionContext
8383
{
8484
[DataMember(Name = "diagnostics")]
85-
public Diagnostic[] Diagnostics { get; set; }
85+
public Diagnostic[]? Diagnostics { get; set; }
8686

8787
public VisualStudio.LanguageServer.Protocol.CodeActionContext ToCodeActionContext() =>
8888
new VisualStudio.LanguageServer.Protocol.CodeActionContext

0 commit comments

Comments
 (0)