diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2020-11-07 23:30:57 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2020-11-07 23:30:57 +0100 |
| commit | b8ca857f075763e2254a84135a72f1dcace5c74c (patch) | |
| tree | b33048beb7f763fdf77bb90eb3dbac4afa772815 /src/server | |
| parent | 9e37eb68998c99fafe18c591c599bc8a5cca6dee (diff) | |
sublime really doesn't seem to like incremental sync, so full sync is supported now.
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/documents.odin | 74 | ||||
| -rw-r--r-- | src/server/requests.odin | 5 | ||||
| -rw-r--r-- | src/server/types.odin | 15 |
3 files changed, 65 insertions, 29 deletions
diff --git a/src/server/documents.odin b/src/server/documents.odin index 7765190..4ccba6e 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -171,47 +171,71 @@ document_apply_changes :: proc(uri_string: string, changes: [dynamic] TextDocume for change in changes { - absolute_range, ok := common.get_absolute_range(change.range, document.text[:document.used_text]); + //for some reason sublime doesn't seem to care even if i tell it to do incremental sync + if range, ok := change.range.(common.Range); ok { - if !ok { - return .ParseError; - } + absolute_range, ok := common.get_absolute_range(range, document.text[:document.used_text]); - //lower bound is before the change - lower := document.text[:absolute_range.start]; + if !ok { + return .ParseError; + } - //new change between lower and upper - middle := change.text; + //lower bound is before the change + lower := document.text[:absolute_range.start]; - //upper bound is after the change - upper := document.text[absolute_range.end:document.used_text]; + //new change between lower and upper + middle := change.text; - //total new size needed - document.used_text = len(lower) + len(change.text) + len(upper); + //upper bound is after the change + upper := document.text[absolute_range.end:document.used_text]; - //Reduce the amount of allocation by allocating more memory than needed - if document.used_text > len(document.text) { - new_text := make([]u8, document.used_text * 2); + //total new size needed + document.used_text = len(lower) + len(change.text) + len(upper); - //join the 3 splices into the text - copy(new_text, lower); - copy(new_text[len(lower):], middle); - copy(new_text[len(lower)+len(middle):], upper); + //Reduce the amount of allocation by allocating more memory than needed + if document.used_text > len(document.text) { + new_text := make([]u8, document.used_text * 2); - delete(document.text); + //join the 3 splices into the text + copy(new_text, lower); + copy(new_text[len(lower):], middle); + copy(new_text[len(lower)+len(middle):], upper); + + delete(document.text); + + document.text = new_text; + } + + else { + //order matters here, we need to make sure we swap the data already in the text before the middle + copy(document.text, lower); + copy(document.text[len(lower)+len(middle):], upper); + copy(document.text[len(lower):], middle); + } - document.text = new_text; } else { - //order matters here, we need to make sure we swap the data already in the text before the middle - copy(document.text, lower); - copy(document.text[len(lower)+len(middle):], upper); - copy(document.text[len(lower):], middle); + + document.used_text = len(change.text); + + if document.used_text > len(document.text) { + new_text := make([]u8, document.used_text * 2); + copy(new_text, change.text); + delete(document.text); + document.text = new_text; + } + + else { + copy(document.text, change.text); + } + } + } + return document_refresh(document, config, writer, true); } diff --git a/src/server/requests.odin b/src/server/requests.odin index 587e444..0c52f65 100644 --- a/src/server/requests.odin +++ b/src/server/requests.odin @@ -231,7 +231,10 @@ request_initialize :: proc(params: json.Value, id: RequestId, config: ^common.Co response := make_response_message( params = ResponseInitializeParams { capabilities = ServerCapabilities { - textDocumentSync = 2, //incremental + textDocumentSync = TextDocumentSyncOptions { + openClose = true, + change = 2, //incremental + }, definitionProvider = true, completionProvider = CompletionOptions { resolveProvider = false, diff --git a/src/server/types.odin b/src/server/types.odin index 61f2cba..2199601 100644 --- a/src/server/types.odin +++ b/src/server/types.odin @@ -77,7 +77,7 @@ MarkupKind :: enum { }; ServerCapabilities :: struct { - textDocumentSync: int, + textDocumentSync: TextDocumentSyncOptions, definitionProvider: bool, completionProvider: CompletionOptions, }; @@ -105,8 +105,12 @@ ClientCapabilities :: struct { textDocument: TextDocumentClientCapabilities, }; +RangeOptional :: union { + common.Range, +}; + TextDocumentContentChangeEvent :: struct { - range: common.Range, + range: RangeOptional, text: string, }; @@ -201,4 +205,9 @@ CompletionItem :: struct { CompletionList :: struct { isIncomplete: bool, items: [] CompletionItem, -};
\ No newline at end of file +}; + +TextDocumentSyncOptions :: struct { + openClose: bool, + change: int, +}
\ No newline at end of file |