...
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using NubLang.Ast;
|
||||
using NubLang.Syntax;
|
||||
using OmniSharp.Extensions.LanguageServer.Protocol;
|
||||
|
||||
@@ -5,9 +6,10 @@ namespace NubLang.LSP;
|
||||
|
||||
public class WorkspaceManager(DiagnosticsPublisher diagnosticsPublisher)
|
||||
{
|
||||
private readonly Dictionary<DocumentUri, SyntaxTree> _files = new();
|
||||
private readonly Dictionary<DocumentUri, SyntaxTree> _syntaxTrees = new();
|
||||
private readonly Dictionary<DocumentUri, CompilationUnit> _compilationUnits = new();
|
||||
|
||||
public void UpdateFile(DocumentUri path)
|
||||
public void UpdateFile(DocumentUri path, bool typeCheck = true)
|
||||
{
|
||||
var text = File.ReadAllText(path.GetFileSystemPath());
|
||||
var tokenizer = new Tokenizer(path.GetFileSystemPath(), text);
|
||||
@@ -19,11 +21,40 @@ public class WorkspaceManager(DiagnosticsPublisher diagnosticsPublisher)
|
||||
var result = parser.Parse(tokenizer.Tokens);
|
||||
diagnosticsPublisher.Publish(path, parser.Diagnostics);
|
||||
|
||||
_files[path] = result;
|
||||
_syntaxTrees[path] = result;
|
||||
|
||||
if (typeCheck)
|
||||
{
|
||||
TypeCheck();
|
||||
}
|
||||
}
|
||||
|
||||
private void TypeCheck()
|
||||
{
|
||||
var modules = Module.Collect(_syntaxTrees.Select(x => x.Value).ToList());
|
||||
|
||||
foreach (var (path, syntaxTree) in _syntaxTrees)
|
||||
{
|
||||
var typeChecker = new TypeChecker(syntaxTree, modules);
|
||||
var result = typeChecker.Check();
|
||||
diagnosticsPublisher.Publish(path, typeChecker.Diagnostics);
|
||||
_compilationUnits[path] = result;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveFile(Uri path)
|
||||
{
|
||||
_files.Remove(path);
|
||||
_syntaxTrees.Remove(path);
|
||||
_compilationUnits.Remove(path);
|
||||
}
|
||||
|
||||
public Dictionary<DocumentUri, CompilationUnit> GetCompilationUnits()
|
||||
{
|
||||
return _compilationUnits;
|
||||
}
|
||||
|
||||
public CompilationUnit? GetCompilationUnit(DocumentUri path)
|
||||
{
|
||||
return _compilationUnits.GetValueOrDefault(path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user