Skip to content

Commit

Permalink
Add fallback in odin check to try all directory with odin code in t…
Browse files Browse the repository at this point in the history
…hem.
  • Loading branch information
DanielGavin committed Mar 10, 2024
1 parent e86f468 commit 89fd8a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
*node_modules
/ols
/odinfmt

ols.json

22 changes: 0 additions & 22 deletions ols.json

This file was deleted.

43 changes: 43 additions & 0 deletions src/server/check.odin
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,50 @@ import "src:common"
//Store uris we have reported on since last save. We use this to clear them on next save.
uris_reported := make([dynamic]string)


//If the user does not specify where to call odin check, it'll just find all directory with odin, and call them seperately.
fallback_find_odin_directories :: proc(config: ^common.Config) -> []string {
walk_proc :: proc(
info: os.File_Info,
in_err: os.Errno,
user_data: rawptr,
) -> (
err: os.Errno,
skip_dir: bool,
) {
data := cast(^[dynamic]string)user_data

if !info.is_dir && filepath.ext(info.name) == ".odin" {
dir := filepath.dir(info.fullpath, context.temp_allocator)
if !slice.contains(data[:], dir) {
append(data, dir)
}
}

return in_err, false
}

data := make([dynamic]string, context.temp_allocator)

if len(config.workspace_folders) > 0 {
if uri, ok := common.parse_uri(
config.workspace_folders[0].uri,
context.temp_allocator,
); ok {
filepath.walk(uri.path, walk_proc, &data)
}
}

return data[:]
}

check :: proc(paths: []string, writer: ^Writer, config: ^common.Config) {
paths := paths

if len(paths) == 0 {
paths = fallback_find_odin_directories(config)
}

data := make([]byte, mem.Kilobyte * 200, context.temp_allocator)

buffer: []byte
Expand Down
12 changes: 2 additions & 10 deletions src/server/requests.odin
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ request_initialize :: proc(
)
}


for format in initialize_params.capabilities.textDocument.hover.contentFormat {
if format == "markdown" {
config.hover_support_md = true
Expand Down Expand Up @@ -1180,16 +1181,7 @@ notification_did_save :: proc(
log.errorf("failed to collect symbols on save %v", ret)
}

if len(config.profile.checker_path) > 0 {
check(config.profile.checker_path[:], writer, config)
} else {
if uri, ok := common.parse_uri(
config.workspace_folders[0].uri,
context.temp_allocator,
); ok {
check({uri.path}, writer, config)
}
}
check(config.profile.checker_path[:], writer, config)

return .None
}
Expand Down

0 comments on commit 89fd8a6

Please sign in to comment.