aboutsummaryrefslogtreecommitdiff
path: root/src/server/documents.odin
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2020-11-18 22:14:33 +0100
committerDanielGavin <danielgavin5@hotmail.com>2020-11-18 22:14:33 +0100
commit3370a5e546ea9355068ba99b5e81f80527d2e582 (patch)
tree5a93eda4e2a5be4ec58d3ddf2595fa7dc1016cb3 /src/server/documents.odin
parentee4a7f64bcb9d6d7b60d5495fc072b2a62b5f790 (diff)
fixed all the memory leaks
Diffstat (limited to 'src/server/documents.odin')
-rw-r--r--src/server/documents.odin45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/server/documents.odin b/src/server/documents.odin
index 35c0940..3d08766 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -8,6 +8,7 @@ import "core:odin/parser"
import "core:odin/ast"
import "core:odin/tokenizer"
import "core:path"
+import "core:mem"
import "shared:common"
@@ -42,6 +43,9 @@ DocumentStorage :: struct {
document_storage: DocumentStorage;
+document_storage_shutdown :: proc() {
+ delete(document_storage.documents);
+}
document_get :: proc(uri_string: string) -> ^Document {
@@ -55,18 +59,12 @@ document_get :: proc(uri_string: string) -> ^Document {
}
/*
- Note(Daniel, Should there be reference counting of documents or just clear everything on workspace change?
- You usually always need the documents that are loaded in core files, your own files, etc.)
- */
-
-
-/*
Client opens a document with transferred text
*/
document_open :: proc(uri_string: string, text: string, config: ^common.Config, writer: ^Writer) -> common.Error {
- uri, parsed_ok := common.parse_uri(uri_string);
+ uri, parsed_ok := common.parse_uri(uri_string, context.allocator);
log.infof("document_open: %v", uri_string);
@@ -87,7 +85,7 @@ document_open :: proc(uri_string: string, text: string, config: ^common.Config,
document.text = transmute([] u8)text;
document.used_text = len(document.text);
- if err := document_refresh(document, config, writer, true); err != .None {
+ if err := document_refresh(document, config, writer); err != .None {
return err;
}
@@ -102,7 +100,7 @@ document_open :: proc(uri_string: string, text: string, config: ^common.Config,
used_text = len(text),
};
- if err := document_refresh(&document, config, writer, true); err != .None {
+ if err := document_refresh(&document, config, writer); err != .None {
return err;
}
@@ -203,11 +201,13 @@ document_apply_changes :: proc(uri_string: string, changes: [dynamic] TextDocume
//log.info(string(document.text[:document.used_text]));
- return document_refresh(document, config, writer, true);
+ return document_refresh(document, config, writer);
}
document_close :: proc(uri_string: string) -> common.Error {
+ log.infof("document_close: %v", uri_string);
+
uri, parsed_ok := common.parse_uri(uri_string, context.temp_allocator);
if !parsed_ok {
@@ -223,21 +223,18 @@ document_close :: proc(uri_string: string) -> common.Error {
document.client_owned = false;
- common.free_ast_file(document.ast);
-
common.delete_uri(document.uri);
delete(document.text);
document.used_text = 0;
-
return .None;
}
-document_refresh :: proc(document: ^Document, config: ^common.Config, writer: ^Writer, parse_imports: bool) -> common.Error {
+document_refresh :: proc(document: ^Document, config: ^common.Config, writer: ^Writer) -> common.Error {
errors, ok := parse_document(document, config);
@@ -323,6 +320,8 @@ parser_warning_handler :: proc(pos: tokenizer.Pos, msg: string, args: ..any) {
parse_document :: proc(document: ^Document, config: ^common.Config) -> ([] ParserError, bool) {
+ context.allocator = context.temp_allocator;
+
p := parser.Parser {
err = parser_error_handler,
warn = parser_warning_handler,
@@ -335,21 +334,10 @@ parse_document :: proc(document: ^Document, config: ^common.Config) -> ([] Parse
src = document.text[:document.used_text],
};
- common.free_ast_file(document.ast);
-
parser.parse_file(&p, &document.ast);
- if document.imports != nil {
-
- for p in document.imports {
- delete(p.name);
- }
-
- delete(document.imports);
- }
-
document.imports = make([]Package, len(document.ast.imports));
- document.package_name = path.dir(document.uri.path, context.allocator); //todo(memory leak)
+ document.package_name = path.dir(document.uri.path, context.temp_allocator);
for imp, index in document.ast.imports {
@@ -367,9 +355,8 @@ parse_document :: proc(document: ^Document, config: ^common.Config) -> ([] Parse
continue;
}
- document.imports[index].name = path.join(dir, p);
+ document.imports[index].name = strings.clone(path.join(elems = {dir, p}, allocator = context.temp_allocator));
document.imports[index].base = path.base(document.imports[index].name, false);
-
}
//relative
@@ -379,7 +366,5 @@ parse_document :: proc(document: ^Document, config: ^common.Config) -> ([] Parse
}
- //fmt.println(document.imports);
-
return current_errors[:], true;
}