diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-08-01 14:37:53 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-08-01 14:37:53 +0200 |
| commit | 8869f3f639c5dcf222d52e78f56996a4d5abf271 (patch) | |
| tree | 84406501a142878d180b35e448daf7dce875b859 /src | |
| parent | bbc6dc4b64f3dc8c9cb9c4671be641f31e4cd327 (diff) | |
Fixes
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/util.odin | 58 | ||||
| -rw-r--r-- | src/common/util_windows.odin | 1 | ||||
| -rw-r--r-- | src/server/check.odin | 11 | ||||
| -rw-r--r-- | src/server/documents.odin | 2 |
4 files changed, 43 insertions, 29 deletions
diff --git a/src/common/util.odin b/src/common/util.odin index b28154e..9359486 100644 --- a/src/common/util.odin +++ b/src/common/util.odin @@ -39,34 +39,38 @@ lookup_in_path :: proc(name: string) -> (string, bool) { return "", false } -run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) { - fp := popen(strings.clone_to_cstring(command, context.temp_allocator), "r") - if fp == nil { - return 0, false, stdout[0:] - } - defer pclose(fp) - - read_buffer: [50]byte - index: int - - for fgets(&read_buffer[0], size_of(read_buffer), fp) != nil { - read := bytes.index_byte(read_buffer[:], 0) - defer index += cast(int)read +when ODIN_OS == .Darwin || ODIN_OS == .Linux { + FILE :: struct {} - if read > 0 && index + cast(int)read <= len(stdout) { - mem.copy(&stdout[index], &read_buffer[0], cast(int)read) + run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) { + fp := popen(strings.clone_to_cstring(command, context.temp_allocator), "r") + if fp == nil { + return 0, false, stdout[0:] + } + defer pclose(fp) + + read_buffer: [50]byte + index: int + + for fgets(&read_buffer[0], size_of(read_buffer), fp) != nil { + read := bytes.index_byte(read_buffer[:], 0) + defer index += cast(int)read + + if read > 0 && index + cast(int)read <= len(stdout) { + mem.copy(&stdout[index], &read_buffer[0], cast(int)read) + } } + + + + return 0, true, stdout[0:index] + } + + foreign libc + { + popen :: proc(command: cstring, type: cstring) -> ^FILE --- + pclose :: proc(stream: ^FILE) -> i32 --- + fgets :: proc "cdecl" (s: [^]byte, n: i32, stream: ^FILE) -> [^]u8 --- + fgetc :: proc "cdecl" (stream: ^FILE) -> i32 --- } - - return 0, true, stdout[0:index] -} - -foreign libc -{ - popen :: proc(command: cstring, type: cstring) -> ^FILE --- - pclose :: proc(stream: ^FILE) -> i32 --- - fgets :: proc "cdecl" (s: [^]byte, n: i32, stream: ^FILE) -> [^]u8 --- - fgetc :: proc "cdecl" (stream: ^FILE) -> i32 --- } - -FILE :: struct {} diff --git a/src/common/util_windows.odin b/src/common/util_windows.odin index b877f4b..23a58cd 100644 --- a/src/common/util_windows.odin +++ b/src/common/util_windows.odin @@ -131,6 +131,7 @@ run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) return exit_code, true, stdout[0:index] } + import "core:mem/virtual" Growing_Arena :: virtual.Growing_Arena diff --git a/src/server/check.odin b/src/server/check.odin index 38a999f..6d57b95 100644 --- a/src/server/check.odin +++ b/src/server/check.odin @@ -46,7 +46,16 @@ check :: proc(uri: common.Uri, writer: ^Writer, config: ^common.Config) { command = "odin" } - if code, ok, buffer = common.run_executable(fmt.tprintf("%v check %s %s -no-entry-point %s 2>&1", command, path.dir(uri.path, context.temp_allocator), strings.to_string(collection_builder), config.checker_args), &data); !ok { + if code, ok, buffer = common.run_executable( + fmt.tprintf("%v check %s %s -no-entry-point %s %s", + command, + path.dir(uri.path, context.temp_allocator), + strings.to_string(collection_builder), + config.checker_args, + ODIN_OS == .Linux || ODIN_OS == .Darwin ? "2>&1" : "", + ), + &data + ); !ok { log.errorf("Odin check failed with code %v for file %v", code, uri.path) return } diff --git a/src/server/documents.odin b/src/server/documents.odin index 9f5be37..d320cf0 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -322,7 +322,7 @@ document_refresh :: proc(document: ^Document, config: ^common.Config, writer: ^W }, }, severity = DiagnosticSeverity.Error, - code = "test", + code = "Syntax", message = error.message, } } |