Continuously update depending files when changing modules

This commit is contained in:
Deukhoofd 2018-12-14 18:49:39 +01:00
parent 856a2cacc4
commit 654ec54879
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
4 changed files with 27 additions and 2 deletions

View File

@ -31,7 +31,8 @@ namespace UpsilonLanguageServer.Services
BoundTypeParser.LoadStaticVariables(File.ReadAllText(staticConfigFile));
}
Session.Settings.ModuleDirectory = Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory);
Session.Settings.ModuleDirectory =
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory)).FullName;
Session.Client.Window.LogMessage(MessageType.Error, Session.Settings.ModuleDirectory);
}
return new InitializeResult(new ServerCapabilities

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using JsonRpc.Standard.Contracts;
using LanguageServer.VsCode.Contracts;
@ -17,7 +18,8 @@ namespace UpsilonLanguageServer.Services
public async Task DidChangeConfiguration(SettingsRoot settings)
{
Session.Settings = settings.UpsilonLanguageServer;
Session.Settings.ModuleDirectory = Path.Combine(RootUri, Session.Settings.ModuleDirectory);
Session.Settings.ModuleDirectory =
new DirectoryInfo(Path.Combine(RootUri, Session.Settings.ModuleDirectory)).FullName;
foreach (var doc in Session.Documents.Values)
{
var diag = await DiagnosticProvider.LintDocument(doc.Document, doc, Session.Settings.MaxNumberOfProblems,
@ -35,6 +37,28 @@ namespace UpsilonLanguageServer.Services
var localPath = change.Uri.AbsolutePath;
if (string.Equals(Path.GetExtension(localPath), ".yup", StringComparison.InvariantCultureIgnoreCase))
{
// If its a module
if (string.Equals(Path.GetDirectoryName(localPath), Session.Settings.ModuleDirectory))
{
var name = Path.GetFileNameWithoutExtension(localPath);
var firstScript = Session.Documents.Values.FirstOrDefault(x => x.Bound != null);
firstScript?.Bound.Script.Options.ModuleHandler.ClearCachedModule(name);
if (change.Type == FileChangeType.Deleted)
{
await Client.Document.PublishDiagnostics(change.Uri, new Diagnostic[0]);
}
foreach (var doc in Session.Documents.Values)
{
if (doc.Bound == null)
continue;
if (!doc.Bound.Script.ModuleDependencies.Any(x => string.Equals(x, name)))
continue;
var diag = await DiagnosticProvider.LintDocument(doc.Document, doc,
Session.Settings.MaxNumberOfProblems, Session.Settings.ModuleDirectory);
await Client.Document.PublishDiagnostics(doc.Document.Uri, diag);
}
}
// If the file has been removed, we will clear the lint result about it.
// Note that pass null to PublishDiagnostics may mess up the client.
if (change.Type == FileChangeType.Deleted)