Skip to content

Commit 2eba982

Browse files
committed
DemoLanguageServer: Clears diagnostic information for deleted files.
1 parent 36eaa45 commit 2eba982

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

Client/VsCode/src/extension.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ const languageServerPaths = [
1616
function activateLanguageServer(context: vscode.ExtensionContext) {
1717
// The server is implemented in an executable application.
1818
let serverModule: string = null;
19-
for (let p of languageServerPaths)
20-
{
19+
for (let p of languageServerPaths) {
2120
p = context.asAbsolutePath(p);
2221
// console.log(p);
23-
if (fs.existsSync(p))
24-
{
22+
if (fs.existsSync(p)) {
2523
serverModule = p;
2624
break;
2725
}
@@ -30,7 +28,7 @@ function activateLanguageServer(context: vscode.ExtensionContext) {
3028
let workPath = path.dirname(serverModule);
3129
console.log(`Use ${serverModule} as server module.`);
3230
console.log(`Work path: ${workPath}.`);
33-
31+
3432

3533
// If the extension is launched in debug mode then the debug server options are used
3634
// Otherwise the run options are used
@@ -46,7 +44,10 @@ function activateLanguageServer(context: vscode.ExtensionContext) {
4644
// Synchronize the setting section 'languageServerExample' to the server
4745
configurationSection: "demoLanguageServer",
4846
// Notify the server about file changes to '.clientrc files contain in the workspace
49-
fileEvents: vscode.workspace.createFileSystemWatcher("**/.clientrc")
47+
fileEvents: [
48+
vscode.workspace.createFileSystemWatcher("**/.clientrc"),
49+
vscode.workspace.createFileSystemWatcher("**/.demo"),
50+
]
5051
},
5152
}
5253

DemoLanguageServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define WAIT_FOR_DEBUGGER
1+
//#define WAIT_FOR_DEBUGGER
22
//#define USE_CONSOLE_READER
33

44
using System;

DemoLanguageServer/Services/TextDocumentService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public void WillSave(TextDocumentIdentifier textDocument, TextDocumentSaveReason
5050
}
5151

5252
[JsonRpcMethod(IsNotification = true)]
53-
public void DidClose(TextDocumentIdentifier textDocument)
53+
public async Task DidClose(TextDocumentIdentifier textDocument)
5454
{
55+
await Client.Document.PublishDiagnostics(textDocument.Uri, new Diagnostic[0]);
5556
Documents.Remove(textDocument);
5657
}
5758

DemoLanguageServer/Services/WorkspaceService.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Text;
45
using System.Threading.Tasks;
56
using JsonRpc.Standard.Contracts;
7+
using LanguageServer.VsCode.Contracts;
68
using Newtonsoft.Json.Linq;
79

810
namespace DemoLanguageServer.Services
@@ -20,5 +22,24 @@ public async Task DidChangeConfiguration(SettingsRoot settings)
2022
await Client.Document.PublishDiagnostics(doc.Uri, diag);
2123
}
2224
}
25+
26+
[JsonRpcMethod(IsNotification = true)]
27+
public async Task DidChangeWatchedFiles(ICollection<FileEvent> changes)
28+
{
29+
foreach (var change in changes)
30+
{
31+
if (!change.Uri.IsFile) continue;
32+
var localPath = change.Uri.AbsolutePath;
33+
if (string.Equals(Path.GetExtension(localPath), ".demo"))
34+
{
35+
// If the file has been removed, we will clear the lint result about it.
36+
// Note that pass null to PublishDiagnostics may mess up the client.
37+
if (change.Type == FileChangeType.Deleted)
38+
{
39+
await Client.Document.PublishDiagnostics(change.Uri, new Diagnostic[0]);
40+
}
41+
}
42+
}
43+
}
2344
}
2445
}

LanguageServer.VsCode/LanguageServer.VsCode.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
<Company />
1010
<Description>A .NET Language Server library for VSCode.</Description>
1111
<Copyright>Copyright 2017 CXuesong</Copyright>
12-
<PackageTags>vscode language-server</PackageTags>
12+
<PackageTags>vscode language-server language-server-protocol</PackageTags>
1313
<NeutralLanguage>en-us</NeutralLanguage>
14+
<PackageProjectUrl>https://github.com/CXuesong/LanguageServer.NET</PackageProjectUrl>
15+
<RepositoryUrl>https://github.com/CXuesong/LanguageServer.NET</RepositoryUrl>
16+
<RepositoryType>git</RepositoryType>
17+
<PackageReleaseNotes>See https://github.com/CXuesong/LanguageServer.NET/releases .</PackageReleaseNotes>
1418
</PropertyGroup>
1519

1620
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

0 commit comments

Comments
 (0)