Skip to content

Commit 75c6594

Browse files
committed
Add LanguageServerExtensions.IsUntitled.
Add Diagnostic.EmptyDiagnostics. Update demo.
1 parent f9e62d0 commit 75c6594

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

DemoLanguageServer/Services/TextDocumentService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using JsonRpc.Standard.Contracts;
77
using JsonRpc.Standard.Server;
8+
using LanguageServer.VsCode;
89
using LanguageServer.VsCode.Contracts;
910
using LanguageServer.VsCode.Server;
1011

@@ -52,7 +53,10 @@ public void WillSave(TextDocumentIdentifier textDocument, TextDocumentSaveReason
5253
[JsonRpcMethod(IsNotification = true)]
5354
public async Task DidClose(TextDocumentIdentifier textDocument)
5455
{
55-
await Client.Document.PublishDiagnostics(textDocument.Uri, new Diagnostic[0]);
56+
if (textDocument.Uri.IsUntitled())
57+
{
58+
await Client.Document.PublishDiagnostics(textDocument.Uri, new Diagnostic[0]);
59+
}
5660
Documents.Remove(textDocument);
5761
}
5862

LanguageServer.VsCode/Contracts/Client/IDocument.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public interface IDocument
1414
/// Diagnostics notification are sent from the server to the client to signal results of validation runs.
1515
/// </summary>
1616
/// <param name="uri">The URI for which diagnostic information is reported.</param>
17-
/// <param name="diagnostics"> An array of diagnostic information items.</param>
17+
/// <param name="diagnostics">An array of diagnostic information items.
18+
/// To clear the existing diagnostics, pass <see cref="Diagnostic.EmptyDiagnostics"/> instead of <c>null</c>.</param>
1819
[JsonRpcMethod(IsNotification = true)]
1920
Task PublishDiagnostics(Uri uri, IEnumerable<Diagnostic> diagnostics);
2021
}

LanguageServer.VsCode/Contracts/Diagnostic.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public enum DiagnosticSeverity
3636
[JsonObject(MemberSerialization.OptIn)]
3737
public class Diagnostic
3838
{
39+
40+
/// <summary>
41+
/// Represents an empty array of <see cref="Diagnostic"/>
42+
/// </summary>
43+
public static readonly Diagnostic[] EmptyDiagnostics = { };
44+
3945
[JsonConstructor]
4046
public Diagnostic()
4147
{

LanguageServer.VsCode/LanguageServer.VsCode.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PackageId>CXuesong.LanguageServer.VsCode</PackageId>
66
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
77
<Authors>CXuesong</Authors>
8-
<Version>0.1.0-int0</Version>
8+
<Version>0.1.0-int1</Version>
99
<Company />
1010
<Description>A .NET Language Server library for VSCode.</Description>
1111
<Copyright>Copyright 2017 CXuesong</Copyright>

LanguageServer.VsCode/JsonRpcHostExtensions.cs renamed to LanguageServer.VsCode/LanguageServerExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,13 @@ public static void UseCancellationHandling(this ServiceHostBuilder builder)
3636
}
3737
});
3838
}
39+
40+
/// <summary>
41+
/// Determines whether the specified document URI indeicates an unsaved document.
42+
/// </summary>
43+
public static bool IsUntitled(this Uri documentUri)
44+
{
45+
return documentUri.Scheme == "untitled";
46+
}
3947
}
4048
}

0 commit comments

Comments
 (0)