diff --git a/Client/package.json b/Client/package.json index 6de8591..e8bfd16 100644 --- a/Client/package.json +++ b/Client/package.json @@ -38,6 +38,11 @@ "type": "number", "default": 100, "description": "Controls the maximum number of problems produced by the server." + }, + "upsilonLanguageServer.moduleDirectory": { + "type": "string", + "default": "./modules", + "description": "The relative path from the workspace where the modules can be found." } } } diff --git a/UpsilonLanguageServer/Lib/Upsilon.dll b/UpsilonLanguageServer/Lib/Upsilon.dll index c1160e1..010d001 100644 Binary files a/UpsilonLanguageServer/Lib/Upsilon.dll and b/UpsilonLanguageServer/Lib/Upsilon.dll differ diff --git a/UpsilonLanguageServer/Lib/Upsilon.pdb b/UpsilonLanguageServer/Lib/Upsilon.pdb index 95cbcc8..bfe8529 100644 Binary files a/UpsilonLanguageServer/Lib/Upsilon.pdb and b/UpsilonLanguageServer/Lib/Upsilon.pdb differ diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs b/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs index dcc2234..0fef31a 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/DiagnosticsProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; using LanguageServer.VsCode.Contracts; using LanguageServer.VsCode.Server; @@ -13,12 +14,11 @@ namespace UpsilonLanguageServer public DiagnosticProvider() { - } public static async Task> LintDocument(TextDocument document, SessionDocument session, - int maxNumberOfProblems) + int maxNumberOfProblems, string modulePath) { var diag = new List(); var content = document.Content; @@ -30,7 +30,7 @@ namespace UpsilonLanguageServer return diag; } - var task = RealLint(document, maxNumberOfProblems, session, content, diag); + var task = RealLint(document, maxNumberOfProblems, session, content, diag, modulePath); // either wait until the script is linted, or until a second has passed (timeout) await Task.WhenAny(task, Task.Delay(1000)); session.IsChanging = false; @@ -44,8 +44,9 @@ namespace UpsilonLanguageServer }; private static async Task RealLint(TextDocument document, int maxNumberOfProblems, SessionDocument session, - string content, List diag) + string content, ICollection diag, string modulePath) { + Options.ScriptLoader.ModulesPath = modulePath; try { using (var script = Executor.ParseInput(content, Options)) @@ -55,10 +56,12 @@ namespace UpsilonLanguageServer foreach (var error in script.Diagnostics.Errors) { diag.Add(ConvertToVsCodeDiagnostic(error)); + if (diag.Count >= maxNumberOfProblems) break; } foreach (var warning in script.Diagnostics.Warnings) { diag.Add(ConvertToVsCodeDiagnostic(warning)); + if (diag.Count >= maxNumberOfProblems) break; } session.Bound = bound; diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs index 2a325e5..5ae55ac 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/InitializationService.cs @@ -12,11 +12,11 @@ namespace UpsilonLanguageServer.Services { public class InitializationService : UpsilonLanguageServiceBase { - [JsonRpcMethod(AllowExtensionData = true)] public InitializeResult Initialize(int processId, Uri rootUri, ClientCapabilities capabilities, JToken initializationOptions = null, string trace = null) { + WorkspaceService.RootUri = rootUri?.AbsolutePath; if (rootUri != null) { var configPath = rootUri.AbsolutePath + "/.upsilon"; @@ -30,6 +30,9 @@ namespace UpsilonLanguageServer.Services { BoundTypeParser.LoadStaticVariables(File.ReadAllText(staticConfigFile)); } + + Session.Settings.ModuleDirectory = Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory); + Session.Client.Window.LogMessage(MessageType.Error, Session.Settings.ModuleDirectory); } return new InitializeResult(new ServerCapabilities { diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs index b7ea2bd..e93a5f1 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/TextDocumentServer.cs @@ -118,7 +118,8 @@ namespace UpsilonLanguageServer.Services // Lint the document when it's changed. var sessionDocument = ((SessionDocument) sender); var doc1 = sessionDocument.Document; - var diag1 = DiagnosticProvider.LintDocument(doc1, sessionDocument, session.Settings.MaxNumberOfProblems); + var diag1 = DiagnosticProvider.LintDocument(doc1, sessionDocument, session.Settings.MaxNumberOfProblems, + session.Settings.ModuleDirectory); if (session.Documents.ContainsKey(doc1.Uri)) { // In case the document has been closed when we were linting… @@ -126,7 +127,8 @@ namespace UpsilonLanguageServer.Services } }; Session.Documents.TryAdd(textDocument.Uri, doc); - var diag = DiagnosticProvider.LintDocument(doc.Document, doc, Session.Settings.MaxNumberOfProblems); + var diag = DiagnosticProvider.LintDocument(doc.Document, doc, Session.Settings.MaxNumberOfProblems, + session.Settings.ModuleDirectory); await Client.Document.PublishDiagnostics(textDocument.Uri, await diag); } diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Services/WorkspaceService.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Services/WorkspaceService.cs index f65e235..2474047 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Services/WorkspaceService.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Services/WorkspaceService.cs @@ -11,13 +11,17 @@ namespace UpsilonLanguageServer.Services [JsonRpcScope(MethodPrefix = "workspace/")] public class WorkspaceService : UpsilonLanguageServiceBase { + public static string RootUri { get; set; } + [JsonRpcMethod(IsNotification = true)] public async Task DidChangeConfiguration(SettingsRoot settings) { Session.Settings = settings.UpsilonLanguageServer; + Session.Settings.ModuleDirectory = Path.Combine(RootUri, Session.Settings.ModuleDirectory); foreach (var doc in Session.Documents.Values) { - var diag = await DiagnosticProvider.LintDocument(doc.Document, doc, Session.Settings.MaxNumberOfProblems); + var diag = await DiagnosticProvider.LintDocument(doc.Document, doc, Session.Settings.MaxNumberOfProblems, + Session.Settings.ModuleDirectory); await Client.Document.PublishDiagnostics(doc.Document.Uri, diag); } } @@ -59,7 +63,8 @@ namespace UpsilonLanguageServer.Services BoundTypeParser.LoadBoundTypes(File.ReadAllText(localPath)); foreach (var doc in Session.Documents.Values) { - var diag = await DiagnosticProvider.LintDocument(doc.Document, doc, Session.Settings.MaxNumberOfProblems); + var diag = await DiagnosticProvider.LintDocument(doc.Document, doc, + Session.Settings.MaxNumberOfProblems, Session.Settings.ModuleDirectory); await Client.Document.PublishDiagnostics(doc.Document.Uri, diag); } } @@ -72,7 +77,8 @@ namespace UpsilonLanguageServer.Services BoundTypeParser.LoadStaticVariables(File.ReadAllText(localPath)); foreach (var doc in Session.Documents.Values) { - var diag = await DiagnosticProvider.LintDocument(doc.Document, doc, Session.Settings.MaxNumberOfProblems); + var diag = await DiagnosticProvider.LintDocument(doc.Document, doc, + Session.Settings.MaxNumberOfProblems, Session.Settings.ModuleDirectory); await Client.Document.PublishDiagnostics(doc.Document.Uri, diag); } } diff --git a/UpsilonLanguageServer/UpsilonLanguageServer/Settings.cs b/UpsilonLanguageServer/UpsilonLanguageServer/Settings.cs index e2a2cc1..31613d7 100644 --- a/UpsilonLanguageServer/UpsilonLanguageServer/Settings.cs +++ b/UpsilonLanguageServer/UpsilonLanguageServer/Settings.cs @@ -8,6 +8,7 @@ namespace UpsilonLanguageServer public class LanguageServerSettings { public int MaxNumberOfProblems { get; set; } = 10; + public string ModuleDirectory { get; set; } = "./modules"; public LanguageServerTraceSettings Trace { get; } = new LanguageServerTraceSettings(); }