hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
document.h
Go to the documentation of this file.
1//
2// Document Store for hoshi-lang LSP server
3//
4
5#ifndef HOSHI_LANG_LSP_DOCUMENT_H
6#define HOSHI_LANG_LSP_DOCUMENT_H
7
8#include <map>
9#include <memory>
10#include <string>
11#include <vector>
12#include <share/def.hpp>
15#include <compiler/ir/IR.h>
18#include "symbolExtractor.h"
19#include "projectIndex.h"
20
21namespace lsp {
22
23struct Document {
24 std::string uri;
25 std::string languageId;
26 int version = 0;
29 yoi::vec<Symbol> symbols; // Symbols defined in this document
30 yoi::vec<Symbol> crossModuleSymbols; // Symbols from imported/used modules (flattened)
32 bool parseSucceeded = false;
33 ProjectIndex *projectIndex = nullptr; // For fallback module resolution
34 std::shared_ptr<yoi::IRModule> irModule; // Type info from the visitor
35 std::shared_ptr<yoi::compilerContext> compilerCtx; // For running the visitor
36
37 ~Document();
38};
39
41public:
42 void setProjectIndex(ProjectIndex *index) { projectIndex = index; }
44 void setCompilerContext(std::shared_ptr<yoi::compilerContext> ctx) { compilerCtx = std::move(ctx); }
45
46 void openDocument(const std::string &uri, const std::string &text,
47 const std::string &languageId, int version);
48 void updateDocument(const std::string &uri, const std::string &text, int version);
49 void closeDocument(const std::string &uri);
50
51 Document *getDocument(const std::string &uri);
52 void reparseDocument(const std::string &uri);
53
54 const std::map<std::string, Document> &getDocuments() const { return documents; }
55
56private:
57 std::map<std::string, Document> documents;
59 std::shared_ptr<yoi::compilerContext> compilerCtx;
60
62 void resolveAndIndexImports(const std::string &uri, Document &doc);
63};
64
65} // namespace lsp
66
67#endif // HOSHI_LANG_LSP_DOCUMENT_H
void closeDocument(const std::string &uri)
Definition document.cpp:47
void openDocument(const std::string &uri, const std::string &text, const std::string &languageId, int version)
Definition document.cpp:25
void resolveAndIndexImports(const std::string &uri, Document &doc)
Resolve import/use references in the document AST and index referenced modules.
Definition document.cpp:160
void reparseDocument(const std::string &uri)
Definition document.cpp:57
void setCompilerContext(std::shared_ptr< yoi::compilerContext > ctx)
Definition document.h:44
ProjectIndex * getProjectIndex()
Definition document.h:43
Document * getDocument(const std::string &uri)
Definition document.cpp:51
std::map< std::string, Document > documents
Definition document.h:57
ProjectIndex * projectIndex
Definition document.h:58
void setProjectIndex(ProjectIndex *index)
Definition document.h:42
std::shared_ptr< yoi::compilerContext > compilerCtx
Definition document.h:59
const std::map< std::string, Document > & getDocuments() const
Definition document.h:54
void updateDocument(const std::string &uri, const std::string &text, int version)
Definition document.cpp:37
std::vector< t > vec
Definition def.hpp:56
std::wstring wstr
Definition def.hpp:51
yoi::vec< Symbol > crossModuleSymbols
Definition document.h:30
yoi::hoshiModule * ast
Definition document.h:28
std::string uri
Definition document.h:24
yoi::vec< Symbol > symbols
Definition document.h:29
yoi::wstr text
Definition document.h:27
ProjectIndex * projectIndex
Definition document.h:33
std::shared_ptr< yoi::compilerContext > compilerCtx
Definition document.h:35
std::string languageId
Definition document.h:25
std::shared_ptr< yoi::IRModule > irModule
Definition document.h:34
yoi::vec< yoi::Diagnostic > diagnostics
Definition document.h:31
bool parseSucceeded
Definition document.h:32