aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-05-22 20:03:40 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2021-05-22 20:03:40 +0200
commitd22445e3f9152d6ca43c10cc5ac5bfad50cb52ae (patch)
tree6a9d184c652b3489032c8abd26242f997749b906 /src/server
parent49f8fbd456c6a185d55f4b3ac46abd9450884af2 (diff)
use the new odin printer package
Diffstat (limited to 'src/server')
-rw-r--r--src/server/format.odin41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/server/format.odin b/src/server/format.odin
index 2520474..d05ae19 100644
--- a/src/server/format.odin
+++ b/src/server/format.odin
@@ -2,8 +2,7 @@ package server
import "shared:common"
-
-//import "core:odin/printer"
+import "core:odin/printer"
FormattingOptions :: struct {
tabSize: uint,
@@ -23,16 +22,40 @@ TextEdit :: struct {
newText: string,
}
-get_complete_format :: proc (document: ^Document) -> ([]TextEdit, bool) {
- /*
+get_complete_format :: proc(document: ^Document) -> ([]TextEdit, bool) {
prnt := printer.make_printer(printer.default_style, context.temp_allocator);
- printer.print_file(&prnt, &document.ast);
+ if document.ast.syntax_error_count > 0 {
+ return {}, true;
+ }
+
+ if len(document.text) == 0 {
+ return {}, true;
+ }
+
+ src := printer.print(&prnt, &document.ast);
+
+ end_line := 0;
+ end_charcter := 0;
+
+ last := document.text[0];
+ line := 0;
+
+ for current_index := 0; current_index < len(document.text); current_index += 1 {
+ current := document.text[current_index];
+
+ if last == '\r' && current == '\n' {
+ line += 1;
+ current_index += 1;
+ } else if current == '\n' {
+ line += 1;
+ }
- end_line := document.ast.decls[len(document.ast.decls) - 1].end.line;
+ last = current;
+ }
edit := TextEdit {
- newText = printer.to_string(prnt),
+ newText = src,
range = {
start = {
character = 0,
@@ -40,7 +63,7 @@ get_complete_format :: proc (document: ^Document) -> ([]TextEdit, bool) {
},
end = {
character = 1,
- line = end_line + 1,
+ line = line,
},
},
};
@@ -50,6 +73,4 @@ get_complete_format :: proc (document: ^Document) -> ([]TextEdit, bool) {
append(&edits, edit);
return edits[:], true;
- */
- return {}, true;
}