aboutsummaryrefslogtreecommitdiff
path: root/src/server/requests.odin
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-03-04 12:17:00 +0100
committerDaniel Gavin <danielgavin5@hotmail.com>2022-03-04 12:17:00 +0100
commit58287455d64ab16091522bf8a358b079ef05daad (patch)
tree7b6655d6d34b5ad6d719523e4938b8002c43d8ab /src/server/requests.odin
parent63d0bd412a8817445d6dc18e79d5d54c94caf401 (diff)
strip colons and update ast to use unions
Diffstat (limited to 'src/server/requests.odin')
-rw-r--r--src/server/requests.odin648
1 files changed, 324 insertions, 324 deletions
diff --git a/src/server/requests.odin b/src/server/requests.odin
index b06f4cd..00af132 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -63,7 +63,7 @@ make_response_message :: proc (id: RequestId, params: ResponseParams) -> Respons
jsonrpc = "2.0",
id = id,
result = params,
- };
+ }
}
make_response_message_error :: proc (id: RequestId, error: ResponseError) -> ResponseMessageError {
@@ -72,7 +72,7 @@ make_response_message_error :: proc (id: RequestId, error: ResponseError) -> Res
jsonrpc = "2.0",
id = id,
error = error,
- };
+ }
}
RequestThreadData :: struct {
@@ -87,157 +87,157 @@ Request :: struct {
}
-requests_sempahore: sync.Semaphore;
-requests_mutex: sync.Mutex;
+requests_sempahore: sync.Semaphore
+requests_mutex: sync.Mutex
-requests: [dynamic]Request;
-deletings: [dynamic]Request;
+requests: [dynamic]Request
+deletings: [dynamic]Request
thread_request_main :: proc(data: rawptr) {
- request_data := cast(^RequestThreadData)data;
+ request_data := cast(^RequestThreadData)data
for common.config.running {
- header, success := read_and_parse_header(request_data.reader);
+ header, success := read_and_parse_header(request_data.reader)
if (!success) {
- log.error("Failed to read and parse header");
- return;
+ log.error("Failed to read and parse header")
+ return
}
- value: json.Value;
- value, success = read_and_parse_body(request_data.reader, header);
+ value: json.Value
+ value, success = read_and_parse_body(request_data.reader, header)
if (!success) {
- log.error("Failed to read and parse body");
- return;
+ log.error("Failed to read and parse body")
+ return
}
- root, ok := value.(json.Object);
+ root, ok := value.(json.Object)
if !ok {
- log.error("No root object");
- return;
+ log.error("No root object")
+ return
}
- id: RequestId;
- id_value: json.Value;
- id_value, ok = root["id"];
+ id: RequestId
+ id_value: json.Value
+ id_value, ok = root["id"]
if ok {
#partial switch v in id_value {
case json.String:
- id = v;
+ id = v
case json.Integer:
- id = v;
+ id = v
case:
- id = 0;
+ id = 0
}
}
- sync.mutex_lock(&requests_mutex);
+ sync.mutex_lock(&requests_mutex)
- method := root["method"].(json.String);
+ method := root["method"].(json.String)
if method == "$/cancelRequest" {
- append(&deletings, Request { id = id });
+ append(&deletings, Request { id = id })
} else if method in notification_map {
- append(&requests, Request { value = root, is_notification = true});
- sync.semaphore_post(&requests_sempahore);
+ append(&requests, Request { value = root, is_notification = true})
+ sync.semaphore_post(&requests_sempahore)
} else {
- append(&requests, Request { id = id, value = root});
- sync.semaphore_post(&requests_sempahore);
+ append(&requests, Request { id = id, value = root})
+ sync.semaphore_post(&requests_sempahore)
}
- sync.mutex_unlock(&requests_mutex);
+ sync.mutex_unlock(&requests_mutex)
- free_all(context.temp_allocator);
+ free_all(context.temp_allocator)
}
}
read_and_parse_header :: proc (reader: ^Reader) -> (Header, bool) {
- header: Header;
+ header: Header
- builder := strings.make_builder(context.temp_allocator);
+ builder := strings.make_builder(context.temp_allocator)
- found_content_length := false;
+ found_content_length := false
for true {
- strings.reset_builder(&builder);
+ strings.reset_builder(&builder)
if !read_until_delimiter(reader, '\n', &builder) {
- log.error("Failed to read with delimiter");
- return header, false;
+ log.error("Failed to read with delimiter")
+ return header, false
}
- message := strings.to_string(builder);
+ message := strings.to_string(builder)
if len(message) == 0 || message[len(message) - 2] != '\r' {
- log.error("No carriage return");
- return header, false;
+ log.error("No carriage return")
+ return header, false
}
if len(message) == 2 {
- break;
+ break
}
- index := strings.last_index_byte(message, ':');
+ index := strings.last_index_byte(message, ':')
if index == -1 {
- log.error("Failed to find semicolon");
- return header, false;
+ log.error("Failed to find semicolon")
+ return header, false
}
- header_name := message[0:index];
- header_value := message[len(header_name) + 2:len(message) - 2];
+ header_name := message[0:index]
+ header_value := message[len(header_name) + 2:len(message) - 2]
if strings.compare(header_name, "Content-Length") == 0 {
if len(header_value) == 0 {
- log.error("Header value has no length");
- return header, false;
+ log.error("Header value has no length")
+ return header, false
}
- value, ok := strconv.parse_int(header_value);
+ value, ok := strconv.parse_int(header_value)
if !ok {
- log.error("Failed to parse content length value");
- return header, false;
+ log.error("Failed to parse content length value")
+ return header, false
}
- header.content_length = value;
+ header.content_length = value
- found_content_length = true;
+ found_content_length = true
} else if strings.compare(header_name, "Content-Type") == 0 {
if len(header_value) == 0 {
- log.error("Header value has no length");
- return header, false;
+ log.error("Header value has no length")
+ return header, false
}
}
}
- return header, found_content_length;
+ return header, found_content_length
}
read_and_parse_body :: proc (reader: ^Reader, header: Header) -> (json.Value, bool) {
- value: json.Value;
+ value: json.Value
- data := make([]u8, header.content_length, context.temp_allocator);
+ data := make([]u8, header.content_length, context.temp_allocator)
if !read_sized(reader, data) {
- log.error("Failed to read body");
- return value, false;
+ log.error("Failed to read body")
+ return value, false
}
- err: json.Error;
+ err: json.Error
- value, err = json.parse(data = data, allocator = context.allocator, parse_integers = true);
+ value, err = json.parse(data = data, allocator = context.allocator, parse_integers = true)
if (err != json.Error.None) {
- log.error("Failed to parse body");
- return value, false;
+ log.error("Failed to parse body")
+ return value, false
}
- return value, true;
+ return value, true
}
call_map : map [string] proc(json.Value, RequestId, ^common.Config, ^Writer) -> common.Error =
@@ -260,7 +260,7 @@ call_map : map [string] proc(json.Value, RequestId, ^common.Config, ^Writer) ->
"textDocument/formatting" = request_format_document,
"odin/inlayHints" = request_inlay_hint,
"textDocument/documentLink" = request_document_links,
-};
+}
notification_map: map [string] bool = {
"textDocument/didOpen" = true,
@@ -271,52 +271,52 @@ notification_map: map [string] bool = {
}
consume_requests :: proc (config: ^common.Config, writer: ^Writer) -> bool {
- temp_requests := make([dynamic]Request, 0, context.temp_allocator);
+ temp_requests := make([dynamic]Request, 0, context.temp_allocator)
- sync.mutex_lock(&requests_mutex);
+ sync.mutex_lock(&requests_mutex)
for d in deletings {
- delete_index := -1;
+ delete_index := -1
for request, i in requests {
if request.id == d.id {
- delete_index := i;
- break;
+ delete_index := i
+ break
}
}
if delete_index != -1 {
- cancel(requests[delete_index].value, requests[delete_index].id, writer, config);
- ordered_remove(&requests, delete_index);
+ cancel(requests[delete_index].value, requests[delete_index].id, writer, config)
+ ordered_remove(&requests, delete_index)
}
}
for request in requests {
- append(&temp_requests, request);
+ append(&temp_requests, request)
}
- sync.mutex_unlock(&requests_mutex);
+ sync.mutex_unlock(&requests_mutex)
- request_index := 0;
+ request_index := 0
for ; request_index < len(temp_requests); request_index += 1 {
- request := temp_requests[request_index];
- call(request.value, request.id, writer, config);
+ request := temp_requests[request_index]
+ call(request.value, request.id, writer, config)
}
- sync.mutex_lock(&requests_mutex);
+ sync.mutex_lock(&requests_mutex)
for i := 0; i < request_index; i += 1 {
- pop_front(&requests);
+ pop_front(&requests)
}
- sync.mutex_unlock(&requests_mutex);
+ sync.mutex_unlock(&requests_mutex)
if request_index != len(temp_requests) {
- sync.semaphore_post(&requests_sempahore);
+ sync.semaphore_post(&requests_sempahore)
}
- sync.semaphore_wait_for(&requests_sempahore);
+ sync.semaphore_wait_for(&requests_sempahore)
- return true;
+ return true
}
@@ -324,47 +324,47 @@ cancel :: proc(value: json.Value, id: RequestId, writer: ^Writer, config: ^commo
response := make_response_message(
id = id,
params = ResponseParams {},
- );
+ )
- send_response(response, writer);
+ send_response(response, writer)
}
call :: proc(value: json.Value, id: RequestId, writer: ^Writer, config: ^common.Config) {
- root := value.(json.Object);
- method := root["method"].(json.String);
+ root := value.(json.Object)
+ method := root["method"].(json.String)
if fn, ok := call_map[method]; !ok {
- response := make_response_message_error(id = id, error = ResponseError {code = .MethodNotFound, message = ""});
- send_error(response, writer);
+ response := make_response_message_error(id = id, error = ResponseError {code = .MethodNotFound, message = ""})
+ send_error(response, writer)
} else {
- err := fn(root["params"], id, config, writer);
+ err := fn(root["params"], id, config, writer)
if err != .None {
response := make_response_message_error(
id = id,
error = ResponseError {code = err, message = ""},
- );
- send_error(response, writer);
+ )
+ send_error(response, writer)
}
}
}
request_initialize :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- initialize_params: RequestInitializeParams;
+ initialize_params: RequestInitializeParams
if unmarshal(params, initialize_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- config.workspace_folders = make([dynamic]common.WorkspaceFolder);
+ config.workspace_folders = make([dynamic]common.WorkspaceFolder)
for s in initialize_params.workspaceFolders {
- append(&config.workspace_folders, s);
+ append(&config.workspace_folders, s)
}
read_ols_config :: proc(file: string, config: ^common.Config, uri: common.Uri) {
@@ -381,111 +381,111 @@ request_initialize :: proc (params: json.Value, id: RequestId, config: ^common.C
if unmarshal(value, ols_config, context.temp_allocator) == .None {
- config.thread_count = ols_config.thread_pool_count;
- config.enable_document_symbols = ols_config.enable_document_symbols;
- config.enable_hover = ols_config.enable_hover;
+ config.thread_count = ols_config.thread_pool_count
+ config.enable_document_symbols = ols_config.enable_document_symbols
+ config.enable_hover = ols_config.enable_hover
config.enable_format = true // ols_config.enable_format;
- config.enable_semantic_tokens = ols_config.enable_semantic_tokens;
- config.enable_procedure_context = ols_config.enable_procedure_context;
- config.enable_snippets = ols_config.enable_snippets;
- config.verbose = ols_config.verbose;
- config.file_log = ols_config.file_log;
- config.formatter = ols_config.formatter;
- config.odin_command = strings.clone(ols_config.odin_command, context.allocator);
- config.checker_args = ols_config.checker_args;
- config.enable_inlay_hints = ols_config.enable_inlay_hints;
+ config.enable_semantic_tokens = ols_config.enable_semantic_tokens
+ config.enable_procedure_context = ols_config.enable_procedure_context
+ config.enable_snippets = ols_config.enable_snippets
+ config.verbose = ols_config.verbose
+ config.file_log = ols_config.file_log
+ config.formatter = ols_config.formatter
+ config.odin_command = strings.clone(ols_config.odin_command, context.allocator)
+ config.checker_args = ols_config.checker_args
+ config.enable_inlay_hints = ols_config.enable_inlay_hints
for p in ols_config.collections {
- forward_path, _ := filepath.to_slash(p.path, context.temp_allocator);
+ forward_path, _ := filepath.to_slash(p.path, context.temp_allocator)
if filepath.is_abs(p.path) {
- config.collections[strings.clone(p.name)] = strings.clone(forward_path);
+ config.collections[strings.clone(p.name)] = strings.clone(forward_path)
} else {
- config.collections[strings.clone(p.name)] = path.join(elems = {uri.path, forward_path}, allocator = context.allocator);
+ config.collections[strings.clone(p.name)] = path.join(elems = {uri.path, forward_path}, allocator = context.allocator)
}
}
if ok := "" in config.collections; !ok {
- config.collections[""] = strings.clone(uri.path);
+ config.collections[""] = strings.clone(uri.path)
}
} else {
- log.errorf("Failed to unmarshal %v", file);
+ log.errorf("Failed to unmarshal %v", file)
}
} else {
- log.errorf("Failed to parse json %v", file);
+ log.errorf("Failed to parse json %v", file)
}
} else {
- log.errorf("Failed to read/find %v", file);
+ log.errorf("Failed to read/find %v", file)
}
}
- project_uri := "";
+ project_uri := ""
if len(config.workspace_folders) > 0 {
- project_uri = config.workspace_folders[0].uri;
+ project_uri = config.workspace_folders[0].uri
} else if initialize_params.rootUri != "" {
- project_uri = initialize_params.rootUri;
+ project_uri = initialize_params.rootUri
}
if uri, ok := common.parse_uri(project_uri, context.temp_allocator); ok {
- ols_config_path := path.join(elems = {uri.path, "ols.json"}, allocator = context.temp_allocator);
- read_ols_config(ols_config_path, config, uri);
+ ols_config_path := path.join(elems = {uri.path, "ols.json"}, allocator = context.temp_allocator)
+ read_ols_config(ols_config_path, config, uri)
}
- when ODIN_OS == "windows" {
- odin_core_env := os.get_env("ODIN_ROOT", context.temp_allocator);
+ when ODIN_OS == .Windows {
+ odin_core_env := os.get_env("ODIN_ROOT", context.temp_allocator)
} else {
- odin_core_env, _ := os.getenv("ODIN_ROOT");
+ odin_core_env, _ := os.getenv("ODIN_ROOT")
}
if "core" not_in config.collections && odin_core_env != "" {
- forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator);
- config.collections["core"] = path.join(elems = {forward_path, "core"}, allocator = context.allocator);
+ forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
+ config.collections["core"] = path.join(elems = {forward_path, "core"}, allocator = context.allocator)
}
if "vendor" not_in config.collections && odin_core_env != "" {
- forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator);
- config.collections["vendor"] = path.join(elems = {forward_path, "vendor"}, allocator = context.allocator);
+ forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
+ config.collections["vendor"] = path.join(elems = {forward_path, "vendor"}, allocator = context.allocator)
}
for format in initialize_params.capabilities.textDocument.hover.contentFormat {
if format == "markdown" {
- config.hover_support_md = true;
+ config.hover_support_md = true
}
}
for format in initialize_params.capabilities.textDocument.completion.documentationFormat {
if format == "markdown" {
- config.completion_support_md = true;
+ config.completion_support_md = true
}
}
- config.enable_snippets &= initialize_params.capabilities.textDocument.completion.completionItem.snippetSupport;
- config.signature_offset_support = initialize_params.capabilities.textDocument.signatureHelp.signatureInformation.parameterInformation.labelOffsetSupport;
+ config.enable_snippets &= initialize_params.capabilities.textDocument.completion.completionItem.snippetSupport
+ config.signature_offset_support = initialize_params.capabilities.textDocument.signatureHelp.signatureInformation.parameterInformation.labelOffsetSupport
- completionTriggerCharacters := []string {".", ">", "#", "\"", "/", ":"};
- signatureTriggerCharacters := []string {"(", ","};
- signatureRetriggerCharacters := []string {","};
+ completionTriggerCharacters := []string {".", ">", "#", "\"", "/", ":"}
+ signatureTriggerCharacters := []string {"(", ","}
+ signatureRetriggerCharacters := []string {","}
- token_type := type_info_of(SemanticTokenTypes).variant.(runtime.Type_Info_Named).base.variant.(runtime.Type_Info_Enum);
- token_modifier := type_info_of(SemanticTokenModifiers).variant.(runtime.Type_Info_Named).base.variant.(runtime.Type_Info_Enum);
+ token_type := type_info_of(SemanticTokenTypes).variant.(runtime.Type_Info_Named).base.variant.(runtime.Type_Info_Enum)
+ token_modifier := type_info_of(SemanticTokenModifiers).variant.(runtime.Type_Info_Named).base.variant.(runtime.Type_Info_Enum)
- token_types := make([]string, len(token_type.names), context.temp_allocator);
- token_modifiers := make([]string, len(token_modifier.names), context.temp_allocator);
+ token_types := make([]string, len(token_type.names), context.temp_allocator)
+ token_modifiers := make([]string, len(token_modifier.names), context.temp_allocator)
for name, i in token_type.names {
if name == "EnumMember" {
- token_types[i] = "enumMember";
+ token_types[i] = "enumMember"
}
else {
- token_types[i] = strings.to_lower(name, context.temp_allocator);
+ token_types[i] = strings.to_lower(name, context.temp_allocator)
}
}
for name, i in token_modifier.names {
- token_modifiers[i] = strings.to_lower(name, context.temp_allocator);
+ token_modifiers[i] = strings.to_lower(name, context.temp_allocator)
}
response := make_response_message(
@@ -523,335 +523,335 @@ request_initialize :: proc (params: json.Value, id: RequestId, config: ^common.C
resolveProvider = false,
},
},
- }, id = id);
+ }, id = id)
- send_response(response, writer);
+ send_response(response, writer)
/*
Temp index here, but should be some background thread that starts the indexing
*/
- index.indexer.dynamic_index = index.make_memory_index(index.make_symbol_collection(context.allocator, config));
+ index.indexer.dynamic_index = index.make_memory_index(index.make_symbol_collection(context.allocator, config))
- index.build_static_index(context.allocator, config);
+ index.build_static_index(context.allocator, config)
/*
Add runtime package
*/
if core, ok := config.collections["core"]; ok {
- when ODIN_OS == "windows" {
- append(&index.indexer.builtin_packages, path.join(strings.to_lower(core, context.temp_allocator), "runtime"));
+ when ODIN_OS == .Windows {
+ append(&index.indexer.builtin_packages, path.join(strings.to_lower(core, context.temp_allocator), "runtime"))
} else {
- append(&index.indexer.builtin_packages, path.join(core, "runtime"));
+ append(&index.indexer.builtin_packages, path.join(core, "runtime"))
}
}
- log.info("Finished indexing");
+ log.info("Finished indexing")
- return .None;
+ return .None
}
request_initialized :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- return .None;
+ return .None
}
request_shutdown :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- response := make_response_message(params = nil, id = id);
+ response := make_response_message(params = nil, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_definition :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- definition_params: TextDocumentPositionParams;
+ definition_params: TextDocumentPositionParams
if unmarshal(params, definition_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(definition_params.textDocument.uri);
+ document := document_get(definition_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- locations, ok2 := get_definition_location(document, definition_params.position);
+ locations, ok2 := get_definition_location(document, definition_params.position)
if !ok2 {
- log.warn("Failed to get definition location");
+ log.warn("Failed to get definition location")
}
if len(locations) == 1 {
- response := make_response_message(params = locations[0], id = id);
- send_response(response, writer);
+ response := make_response_message(params = locations[0], id = id)
+ send_response(response, writer)
} else {
- response := make_response_message(params = locations, id = id);
- send_response(response, writer);
+ response := make_response_message(params = locations, id = id)
+ send_response(response, writer)
}
- return .None;
+ return .None
}
request_completion :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- completition_params: CompletionParams;
+ completition_params: CompletionParams
if unmarshal(params, completition_params, context.temp_allocator) != .None {
- log.error("Failed to unmarshal completion request");
- return .ParseError;
+ log.error("Failed to unmarshal completion request")
+ return .ParseError
}
- document := document_get(completition_params.textDocument.uri);
+ document := document_get(completition_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- list: CompletionList;
- list, ok = get_completion_list(document, completition_params.position, completition_params.context_);
+ list: CompletionList
+ list, ok = get_completion_list(document, completition_params.position, completition_params.context_)
if !ok {
- return .InternalError;
+ return .InternalError
}
- response := make_response_message(params = list, id = id);
+ response := make_response_message(params = list, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_signature_help :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- signature_params: SignatureHelpParams;
+ signature_params: SignatureHelpParams
if unmarshal(params, signature_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(signature_params.textDocument.uri);
+ document := document_get(signature_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- help: SignatureHelp;
- help, ok = get_signature_information(document, signature_params.position);
+ help: SignatureHelp
+ help, ok = get_signature_information(document, signature_params.position)
if !ok {
- return .InternalError;
+ return .InternalError
}
- response := make_response_message(params = help, id = id);
+ response := make_response_message(params = help, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_format_document :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- format_params: DocumentFormattingParams;
+ format_params: DocumentFormattingParams
if unmarshal(params, format_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(format_params.textDocument.uri);
+ document := document_get(format_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- edit: []TextEdit;
- edit, ok = get_complete_format(document, config);
+ edit: []TextEdit
+ edit, ok = get_complete_format(document, config)
if !ok {
- return .InternalError;
+ return .InternalError
}
- response := make_response_message(params = edit, id = id);
+ response := make_response_message(params = edit, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
notification_exit :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- config.running = false;
- return .None;
+ config.running = false
+ return .None
}
notification_did_open :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- log.error("Failed to parse open document notification");
- return .ParseError;
+ log.error("Failed to parse open document notification")
+ return .ParseError
}
- open_params: DidOpenTextDocumentParams;
+ open_params: DidOpenTextDocumentParams
if unmarshal(params, open_params, context.allocator) != .None {
- log.error("Failed to parse open document notification");
- return .ParseError;
+ log.error("Failed to parse open document notification")
+ return .ParseError
}
if n := document_open(open_params.textDocument.uri, open_params.textDocument.text, config, writer); n != .None {
- return .InternalError;
+ return .InternalError
}
- return .None;
+ return .None
}
notification_did_change :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- change_params: DidChangeTextDocumentParams;
+ change_params: DidChangeTextDocumentParams
if unmarshal(params, change_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document_apply_changes(change_params.textDocument.uri, change_params.contentChanges, config, writer);
+ document_apply_changes(change_params.textDocument.uri, change_params.contentChanges, config, writer)
- return .None;
+ return .None
}
notification_did_close :: proc(params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- close_params: DidCloseTextDocumentParams;
+ close_params: DidCloseTextDocumentParams
if unmarshal(params, close_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
if n := document_close(close_params.textDocument.uri); n != .None {
- return .InternalError;
+ return .InternalError
}
- return .None;
+ return .None
}
notification_did_save :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- save_params: DidSaveTextDocumentParams;
+ save_params: DidSaveTextDocumentParams
if unmarshal(params, save_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- uri: common.Uri;
+ uri: common.Uri
if uri, ok = common.parse_uri(save_params.textDocument.uri, context.temp_allocator); !ok {
- return .ParseError;
+ return .ParseError
}
- fullpath := uri.path;
+ fullpath := uri.path
p := parser.Parser {
err = index.log_error_handler,
warn = index.log_warning_handler,
- };
+ }
- dir := filepath.base(filepath.dir(fullpath, context.temp_allocator));
+ dir := filepath.base(filepath.dir(fullpath, context.temp_allocator))
- pkg := new(ast.Package);
- pkg.kind = .Normal;
- pkg.fullpath = fullpath;
- pkg.name = dir;
+ pkg := new(ast.Package)
+ pkg.kind = .Normal
+ pkg.fullpath = fullpath
+ pkg.name = dir
if dir == "runtime" {
- pkg.kind = .Runtime;
+ pkg.kind = .Runtime
}
file := ast.File {
fullpath = fullpath,
src = save_params.text,
pkg = pkg,
- };
+ }
- ok = parser.parse_file(&p, &file);
+ ok = parser.parse_file(&p, &file)
if !ok {
- log.errorf("error in parse file for indexing %v", fullpath);
+ log.errorf("error in parse file for indexing %v", fullpath)
}
for key, value in index.indexer.dynamic_index.collection.symbols {
- when ODIN_OS == "windows"{
- uri := strings.to_lower(save_params.textDocument.uri, context.temp_allocator);
+ when ODIN_OS == .Windows {
+ uri := strings.to_lower(save_params.textDocument.uri, context.temp_allocator)
} else {
- uri := save_params.textDocument.uri;
+ uri := save_params.textDocument.uri
}
if value.uri == uri {
- index.free_symbol(value, context.allocator);
- index.indexer.dynamic_index.collection.symbols[key] = {};
+ index.free_symbol(value, context.allocator)
+ index.indexer.dynamic_index.collection.symbols[key] = {}
}
}
if ret := index.collect_symbols(&index.indexer.dynamic_index.collection, file, uri.uri); ret != .None {
- log.errorf("failed to collect symbols on save %v", ret);
+ log.errorf("failed to collect symbols on save %v", ret)
}
- check(uri, writer, config);
+ check(uri, writer, config)
- return .None;
+ return .None
}
request_semantic_token_full :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- semantic_params: SemanticTokensParams;
+ semantic_params: SemanticTokensParams
if unmarshal(params, semantic_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(semantic_params.textDocument.uri);
+ document := document_get(semantic_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
range := common.Range {
@@ -861,184 +861,184 @@ request_semantic_token_full :: proc (params: json.Value, id: RequestId, config:
end = common.Position {
line = 9000000, //should be enough
},
- };
+ }
- symbols: SemanticTokens;
+ symbols: SemanticTokens
if config.enable_semantic_tokens {
if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok {
- symbols = get_semantic_tokens(document, range, cache_symbols);
+ symbols = get_semantic_tokens(document, range, cache_symbols)
}
}
- response := make_response_message(params = symbols, id = id);
+ response := make_response_message(params = symbols, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_semantic_token_range :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .None;
+ return .None
}
- semantic_params: SemanticTokensRangeParams;
+ semantic_params: SemanticTokensRangeParams
if unmarshal(params, semantic_params, context.temp_allocator) != .None {
- return .None;
+ return .None
}
- document := document_get(semantic_params.textDocument.uri);
+ document := document_get(semantic_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- symbols: SemanticTokens;
+ symbols: SemanticTokens
if config.enable_semantic_tokens {
if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok {
- symbols = get_semantic_tokens(document, semantic_params.range, cache_symbols);
+ symbols = get_semantic_tokens(document, semantic_params.range, cache_symbols)
}
}
- response := make_response_message(params = symbols, id = id);
+ response := make_response_message(params = symbols, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_document_symbols :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- symbol_params: DocumentSymbolParams;
+ symbol_params: DocumentSymbolParams
if unmarshal(params, symbol_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(symbol_params.textDocument.uri);
+ document := document_get(symbol_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- symbols := get_document_symbols(document);
+ symbols := get_document_symbols(document)
- response := make_response_message(params = symbols, id = id);
+ response := make_response_message(params = symbols, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_hover :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- hover_params: HoverParams;
+ hover_params: HoverParams
if unmarshal(params, hover_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(hover_params.textDocument.uri);
+ document := document_get(hover_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- hover: Hover;
- hover, ok = get_hover_information(document, hover_params.position);
+ hover: Hover
+ hover, ok = get_hover_information(document, hover_params.position)
if !ok {
- return .InternalError;
+ return .InternalError
}
- response := make_response_message(params = hover, id = id);
+ response := make_response_message(params = hover, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_inlay_hint :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- inlay_params: InlayParams;
+ inlay_params: InlayParams
if unmarshal(params, inlay_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(inlay_params.textDocument.uri);
+ document := document_get(inlay_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- hints: []InlayHint;
+ hints: []InlayHint
if cache_symbols, ok := file_resolve_cache.files[document.uri.uri]; ok {
- hints, ok = get_inlay_hints(document, cache_symbols);
+ hints, ok = get_inlay_hints(document, cache_symbols)
}
if !ok {
- return .InternalError;
+ return .InternalError
}
- response := make_response_message(params = hints, id = id);
+ response := make_response_message(params = hints, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
}
request_document_links :: proc (params: json.Value, id: RequestId, config: ^common.Config, writer: ^Writer) -> common.Error {
- params_object, ok := params.(json.Object);
+ params_object, ok := params.(json.Object)
if !ok {
- return .ParseError;
+ return .ParseError
}
- link_params: DocumentLinkParams;
+ link_params: DocumentLinkParams
if unmarshal(params, link_params, context.temp_allocator) != .None {
- return .ParseError;
+ return .ParseError
}
- document := document_get(link_params.textDocument.uri);
+ document := document_get(link_params.textDocument.uri)
if document == nil {
- return .InternalError;
+ return .InternalError
}
- links: []DocumentLink;
+ links: []DocumentLink
- links, ok = get_document_links(document);
+ links, ok = get_document_links(document)
if !ok {
- return .InternalError;
+ return .InternalError
}
- response := make_response_message(params = links, id = id);
+ response := make_response_message(params = links, id = id)
- send_response(response, writer);
+ send_response(response, writer)
- return .None;
+ return .None
} \ No newline at end of file