aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2022-05-19 22:36:35 +0200
committerDaniel Gavin <danielgavin5@hotmail.com>2022-05-19 22:36:35 +0200
commiteda3110541a5a9f6f5e3b9428139f5d060e6a3ae (patch)
tree8b74d6bfde2f3206e208cca5d3a32c7d1b2f3cd2
parentcac294ccb3baf33aa91a7dbcbc17b538c92a23c7 (diff)
parentc85e82db9d62d4a061b16d80b3c26665edaad9fe (diff)
Merge branch 'master' into index-refractor
-rw-r--r--README.md22
-rw-r--r--build.bat10
-rw-r--r--src/common/util_windows.odin73
-rw-r--r--src/odin/printer/visit.odin8
-rw-r--r--src/server/requests.odin10
-rw-r--r--src/server/symbol.odin2
-rw-r--r--tools/odinfmt/main.odin2
7 files changed, 53 insertions, 74 deletions
diff --git a/README.md b/README.md
index fcefd75..437d077 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# ols
Language server for Odin. This project is still in early development.
-**Status**: Apple M1 does not currently work.
+**Status**: Works on all platforms.
## Table Of Contents
- [Installation](#installation)
@@ -69,20 +69,12 @@ Configuration of the LSP:
{
"odin":
{
- "command":
- [
- "C:/path/to/ols"
- ],
- "enabled": true,
- "languageId": "odin",
- "scopes":
- [
- "source.odin"
- ],
- "syntaxes":
- [
- "Packages/User/sublime-odin/Odin.sublime-syntax"
- ]
+ "command":
+ [
+ "C:/path/to/ols.exe"
+ ],
+ "enabled": false, // true for globally-enabled, but not required due to 'Enable In Project' command
+ "selector": "source.odin",
}
},
"only_show_lsp_completions": true,
diff --git a/build.bat b/build.bat
index 4b09447..7267247 100644
--- a/build.bat
+++ b/build.bat
@@ -2,15 +2,15 @@
if "%1" == "CI" (
- "Odin/odin.exe" test tests -collection:shared=src -debug -opt:0
+ "Odin/odin.exe" test tests -collection:shared=src -debug
if %errorlevel% neq 0 exit 1
- "Odin/odin.exe" build src\ -show-timings -collection:shared=src -out:ols -opt:2 -thread-count:1
+ "Odin/odin.exe" build src\ -show-timings -collection:shared=src -out:ols.exe -o:speed -thread-count:1
) else if "%1" == "test" (
- odin test tests -collection:shared=src -opt:0
+ odin test tests -collection:shared=src -debug
) else if "%1" == "single_test" (
odin test tests -collection:shared=src -test-name:%2
) else if "%1" == "debug" (
- odin build src\ -show-timings -microarch:native -collection:shared=src -out:ols -opt:0 -debug
+ odin build src\ -show-timings -collection:shared=src -out:ols.exe -o:speed -no-bounds-check -debug
) else (
- odin build src\ -show-timings -microarch:native -collection:shared=src -out:ols -opt:2 -no-bounds-check
+ odin build src\ -show-timings -microarch:native -collection:shared=src -out:ols.exe -o:speed -no-bounds-check
) \ No newline at end of file
diff --git a/src/common/util_windows.odin b/src/common/util_windows.odin
index d08d593..5724275 100644
--- a/src/common/util_windows.odin
+++ b/src/common/util_windows.odin
@@ -5,7 +5,7 @@ import "core:mem"
import "core:fmt"
import "core:log"
-import "core:sys/win32"
+import win32 "core:sys/windows"
FORMAT_MESSAGE_FROM_SYSTEM :: 0x00001000
FORMAT_MESSAGE_IGNORE_INSERTS :: 0x00000200
@@ -15,22 +15,20 @@ foreign import kernel32 "system:kernel32.lib"
@(default_calling_convention = "std")
foreign kernel32 {
- @(link_name = "CreatePipe") create_pipe :: proc(hReadPipe, hWritePipe: ^win32.Handle, lpPipeAttributes: ^win32.Security_Attributes, nSize: i32) -> i32 ---
- @(link_name = "GetFinalPathNameByHandleA") get_final_pathname_by_handle_a :: proc(handle: win32.Handle, lpszFilePath: cstring, cchFilePath: u32, dwFlags: u32) -> u32 ---
@(link_name = "FormatMessageA")
format_message_a :: proc(
- flags: i32,
+ flags: u32,
source: rawptr,
- message_id: i32,
- langauge_id: i32,
+ message_id: u32,
+ langauge_id: u32,
buffer: cstring,
- size: i32,
+ size: u32,
va: rawptr,
- ) -> i32 ---
+ ) -> u32 ---
}
get_case_sensitive_path :: proc(path: string, allocator := context.temp_allocator) -> string {
- file := win32.create_file_a(strings.clone_to_cstring(path, context.temp_allocator), 0, win32.FILE_SHARE_READ, nil, win32.OPEN_EXISTING, win32.FILE_FLAG_BACKUP_SEMANTICS, nil)
+ file := win32.CreateFileW(&win32.utf8_to_utf16(path)[0], 0, win32.FILE_SHARE_READ, nil, win32.OPEN_EXISTING, win32.FILE_FLAG_BACKUP_SEMANTICS, nil)
if(file == win32.INVALID_HANDLE)
{
@@ -38,17 +36,18 @@ get_case_sensitive_path :: proc(path: string, allocator := context.temp_allocato
return "";
}
- buffer := make([]u8, 512, context.temp_allocator)
+ buffer := make([]u16, 512, context.temp_allocator)
- ret := get_final_pathname_by_handle_a(file, cast(cstring)&buffer[0], cast(u32)len(buffer), 0)
+ ret := win32.GetFinalPathNameByHandleW(file, &buffer[0], cast(u32)len(buffer), 0)
- return strings.clone_from_cstring(cast(cstring)&buffer[4], allocator)
+ res, _ := win32.utf16_to_utf8(buffer, allocator)
+ return res
}
log_last_error :: proc() {
err_text: [512]byte
- err := win32.get_last_error()
+ err := win32.GetLastError()
error_string := cstring(&err_text[0])
@@ -67,50 +66,46 @@ log_last_error :: proc() {
run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte) {
+ stdout_read: win32.HANDLE
+ stdout_write: win32.HANDLE
- stdout_read: win32.Handle
- stdout_write: win32.Handle
+ attributes: win32.SECURITY_ATTRIBUTES
+ attributes.nLength = size_of(win32.SECURITY_ATTRIBUTES)
+ attributes.bInheritHandle = true
+ attributes.lpSecurityDescriptor = nil
- command := strings.clone_to_cstring(command, context.temp_allocator)
-
- attributes: win32.Security_Attributes
- attributes.length = size_of(win32.Security_Attributes)
- attributes.inherit_handle = true
- attributes.security_descriptor = nil
-
- if create_pipe(&stdout_read, &stdout_write, &attributes, 0) == 0 {
+ if win32.CreatePipe(&stdout_read, &stdout_write, &attributes, 0) == false {
return 0, false, stdout[0:]
}
- if !win32.set_handle_information(stdout_read, win32.HANDLE_FLAG_INHERIT, 0) {
+ if !win32.SetHandleInformation(stdout_read, win32.HANDLE_FLAG_INHERIT, 0) {
return 0, false, stdout[0:]
}
- startup_info: win32.Startup_Info
- process_info: win32.Process_Information
+ startup_info: win32.STARTUPINFO
+ process_info: win32.PROCESS_INFORMATION
- startup_info.cb = size_of(win32.Startup_Info)
+ startup_info.cb = size_of(win32.STARTUPINFO)
- startup_info.stderr = stdout_write
- startup_info.stdout = stdout_write
- startup_info.flags |= win32.STARTF_USESTDHANDLES
+ startup_info.hStdError = stdout_write
+ startup_info.hStdOutput = stdout_write
+ startup_info.dwFlags |= win32.STARTF_USESTDHANDLES
- if !win32.create_process_a(nil, command, nil, nil, true, 0, nil, nil, &startup_info, &process_info) {
+ if !win32.CreateProcessW(nil, &win32.utf8_to_utf16(command)[0], nil, nil, true, 0, nil, nil, &startup_info, &process_info) {
return 0, false, stdout[0:]
}
- win32.close_handle(stdout_write)
+ win32.CloseHandle(stdout_write)
index: int
- read: i32
+ read: u32
read_buffer: [50]byte
- success: win32.Bool = true
+ success: win32.BOOL = true
for success {
-
- success = win32.read_file(stdout_read, &read_buffer[0], len(read_buffer), &read, nil)
+ success = win32.ReadFile(stdout_read, &read_buffer[0], len(read_buffer), &read, nil)
if read > 0 && index + cast(int)read <= len(stdout) {
mem.copy(&stdout[index], &read_buffer[0], cast(int)read)
@@ -123,11 +118,11 @@ run_executable :: proc(command: string, stdout: ^[]byte) -> (u32, bool, []byte)
exit_code: u32
- win32.wait_for_single_object(process_info.process, win32.INFINITE)
+ win32.WaitForSingleObject(process_info.hProcess, win32.INFINITE)
- win32.get_exit_code_process(process_info.process, &exit_code)
+ win32.GetExitCodeProcess(process_info.hProcess, &exit_code)
- win32.close_handle(stdout_read)
+ win32.CloseHandle(stdout_read)
return exit_code, true, stdout[0:index]
} \ No newline at end of file
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin
index 5ae9a78..f95fb3b 100644
--- a/src/odin/printer/visit.odin
+++ b/src/odin/printer/visit.odin
@@ -1054,10 +1054,6 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, called_from: Expr_Called_Type =
case .shared_nil:
document = cons_with_opl(document, text("#shared_nil"))
}
-
- if v.kind == .maybe {
- document = cons_with_opl(document, text("#maybe"))
- }
document = cons_with_nopl(document, push_where_clauses(p, v.where_clauses))
@@ -1171,9 +1167,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, called_from: Expr_Called_Type =
//We enforce a break if comments exists inside the call args
if contains_comments {
document = enforce_break(document)
- } else {
- document = group(document)
- }
+ }
return document
case ^Typeid_Type:
diff --git a/src/server/requests.odin b/src/server/requests.odin
index b30b18c..a217f27 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -318,7 +318,9 @@ consume_requests :: proc (config: ^common.Config, writer: ^Writer) -> bool {
sync.sema_post(&requests_sempahore)
}
- sync.sema_wait(&requests_sempahore)
+ if common.config.running {
+ sync.sema_wait(&requests_sempahore)
+ }
return true
}
@@ -446,11 +448,7 @@ request_initialize :: proc (params: json.Value, id: RequestId, config: ^common.C
read_ols_config(ols_config_path, config, uri)
}
- 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.get_env("ODIN_ROOT", context.temp_allocator)
if "core" not_in config.collections && odin_core_env != "" {
forward_path, _ := filepath.to_slash(odin_core_env, context.temp_allocator)
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index 791c609..3a119ce 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -143,7 +143,7 @@ SymbolType :: enum {
Constant = 21,
Struct = 22,
Union = 7,
- Unresolved = 9999,
+ Unresolved = 1, //Use text if not being able to resolve it.
}
new_clone_symbol :: proc(data: Symbol, allocator := context.allocator) -> (^Symbol) {
diff --git a/tools/odinfmt/main.odin b/tools/odinfmt/main.odin
index 45bbf81..6fca27f 100644
--- a/tools/odinfmt/main.odin
+++ b/tools/odinfmt/main.odin
@@ -66,7 +66,7 @@ walk_files :: proc(info: os.File_Info, in_err: os.Errno) -> (err: os.Errno, skip
main :: proc() {
arena: mem.Arena;
- mem.init_arena(&arena, make([]byte, mem.megabytes(20)));
+ mem.init_arena(&arena, make([]byte, 20 * mem.Megabyte));
arena_allocator := mem.arena_allocator(&arena);