aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2020-11-27 01:36:39 +0100
committerDanielGavin <danielgavin5@hotmail.com>2020-11-27 01:36:39 +0100
commita4a54cedcaf53beb40fc087b26f0f1ec31b6574f (patch)
tree4396d0a2add8c02bfba7c7b4cb12b15aa145f2c8 /src
parent1af0f32800032022f7addbe5ce706a6f13767aba (diff)
add support for json configuration in the workspace
Diffstat (limited to 'src')
-rw-r--r--src/main.odin7
-rw-r--r--src/server/requests.odin39
-rw-r--r--src/server/types.odin9
3 files changed, 46 insertions, 9 deletions
diff --git a/src/main.odin b/src/main.odin
index 1051e24..6246ba0 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -37,15 +37,8 @@ run :: proc(reader: ^server.Reader, writer: ^server.Writer) {
//temporary collections being set manually, need to get client configuration set up.
config.collections = make(map [string] string);
- config.collections["core"] = strings.to_lower("c:/Users/danie/OneDrive/Desktop/Computer_Science/Odin/core");
- config.collections["shared"] = strings.to_lower("c:/Users/danie/OneDrive/Desktop/Computer_Science/ols/src");
-
log.info("Starting Odin Language Server");
- index.build_static_index(context.allocator, &config);
-
- log.info("Finished indexing");
-
config.running = true;
for config.running {
diff --git a/src/server/requests.odin b/src/server/requests.odin
index abcb59e..c84a3bd 100644
--- a/src/server/requests.odin
+++ b/src/server/requests.odin
@@ -8,9 +8,11 @@ import "core:strings"
import "core:slice"
import "core:strconv"
import "core:encoding/json"
+import "core:path"
-import "shared:common"
+import "shared:common"
+import "shared:index"
Header :: struct {
content_length: int,
@@ -219,7 +221,32 @@ request_initialize :: proc(params: json.Value, id: RequestId, config: ^common.Co
config.workspace_folders = make([dynamic]common.WorkspaceFolder);
for s in initialize_params.workspaceFolders {
- append_elem(&config.workspace_folders, s);
+ append(&config.workspace_folders, s);
+ }
+
+ //right now just look at the first workspace - TODO(daniel, add multiple workspace support)
+ if uri, ok := common.parse_uri(config.workspace_folders[0].uri, context.temp_allocator); ok {
+
+ ols_config_path := path.join(elems = {uri.path, "ols.json"}, allocator = context.temp_allocator);
+
+ if data, ok := os.read_entire_file(ols_config_path, context.temp_allocator); ok {
+
+ if value, err := json.parse(data = data, allocator = context.temp_allocator, parse_integers = true); err == .None {
+
+ ols_config: OlsConfig;
+
+ if unmarshal(value, ols_config, context.temp_allocator) == .None {
+
+ for p in ols_config.collections {
+ config.collections[strings.clone(p.name)] = strings.clone(strings.to_lower(p.path, context.temp_allocator));
+ }
+
+ }
+
+ }
+
+ }
+
}
for format in initialize_params.capabilities.textDocument.hover.contentFormat {
@@ -254,6 +281,14 @@ request_initialize :: proc(params: json.Value, id: RequestId, config: ^common.Co
id = id,
);
+ /*
+ Temp index here, but should be some background thread that starts the indexing
+ */
+
+ index.build_static_index(context.allocator, config);
+
+ log.info("Finished indexing");
+
send_response(response, writer);
return .None;
diff --git a/src/server/types.odin b/src/server/types.odin
index d957041..e22d0ad 100644
--- a/src/server/types.odin
+++ b/src/server/types.odin
@@ -252,4 +252,13 @@ SignatureInformation :: struct {
ParameterInformation :: struct {
label: [2] int,
+};
+
+OlsConfig :: struct {
+ collections: [dynamic] OlsConfigCollection,
+};
+
+OlsConfigCollection :: struct {
+ name: string,
+ path: string,
}; \ No newline at end of file