1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package server
import "core:path/filepath"
import "src:common"
import "src:odin/format"
import "src:odin/printer"
FormattingOptions :: struct {
tabSize: uint,
insertSpaces: bool, //tabs or spaces
trimTrailingWhitespace: bool,
insertFinalNewline: bool,
trimFinalNewlines: bool,
}
DocumentFormattingParams :: struct {
textDocument: TextDocumentIdentifier,
options: FormattingOptions,
}
get_complete_format :: proc(document: ^Document, config: ^common.Config) -> ([]TextEdit, bool) {
if document.ast.syntax_error_count > 0 {
return {}, true
}
if len(document.text) == 0 {
return {}, true
}
style := format.find_config_file_or_default(filepath.dir(document.fullpath, context.temp_allocator))
prnt := printer.make_printer(style, context.temp_allocator)
src := printer.print(&prnt, &document.ast)
if prnt.errored_out {
return {}, true
}
edit := TextEdit {
newText = src,
range = common.get_document_range(document.text[0:document.used_text]),
}
edits := make([dynamic]TextEdit, context.temp_allocator)
append(&edits, edit)
return edits[:], true
}
|