Skip to content

Commit fbb87ab

Browse files
committed
Project-specific settings
1 parent f4c12db commit fbb87ab

3 files changed

Lines changed: 50 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121
Note: This package has been designed for NWN2, but it should work with NWN1 as
2222
well.
2323

24+
# Configuration
25+
26+
Global preferences can be found in _Preferences -> Package settings -> STNeverwinterScript -> Settings_
27+
28+
Project-specific preferences can be set in the `.sublime-project` file:
29+
```json
30+
{
31+
"settings": {
32+
"nwscript": {
33+
"compiler_args": ["-q", "-o", "-y", "-v1.70", "-e"],
34+
}
35+
}
36+
}
37+
```
38+
2439
# Installation
2540

2641
## Compiler installation (required for using this package)

‎nwscript_builder.py‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import re
99
import time
10+
from typing import Any
1011

1112
def plugin_loaded():
1213
nwscript_builder.settings = sublime.load_settings('nwscript.sublime-settings')
@@ -54,7 +55,15 @@ def __init__(self, window: sublime.Window):
5455
self.cache = {}
5556
self.cached_include_paths = None
5657

58+
def get_settings_value(self, key: str) -> Any:
59+
proj = self.window.project_data()
60+
for k in ("settings", "nwscript", key):
61+
if proj is not None:
62+
proj = proj.get(k)
63+
if proj is not None:
64+
return proj
5765

66+
return self.settings.get(key)
5867

5968
# Setup build results pane and start run_build in a side thread
6069
def run(self, build_type="smart", kill=False, **kargs):
@@ -96,6 +105,8 @@ def run(self, build_type="smart", kill=False, **kargs):
96105
# Main build function
97106
def run_build(self, working_dir: str, build_type: str):
98107
# Stop currently running processes
108+
self.window.project_data()
109+
99110
if self.build_lock.locked():
100111
self.print_build_results("STOPPING CURRENT BUILD\n")
101112
self.stop_build = True
@@ -169,7 +180,7 @@ def run_build(self, working_dir: str, build_type: str):
169180

170181

171182
def init_includes_cache(self) -> None:
172-
cache = self.settings.get("include_path")
183+
cache = self.get_settings_value("include_path")
173184

174185
# Check if include list changed
175186
if self.cached_include_paths == cache:
@@ -349,7 +360,7 @@ def recurr_get_deps_latest_nss_mtime(curr_script_name, included_from, explored_s
349360

350361
# Search through current dir and include paths to find a given script
351362
def find_script_by_name(self, working_dir, script_name) -> Script:
352-
for folder in [working_dir] + self.settings.get("include_path"):
363+
for folder in [working_dir] + self.get_settings_value("include_path"):
353364
script = self.cache[folder].scripts.get(script_name, None)
354365
if script is not None:
355366
return script
@@ -383,9 +394,9 @@ def parse_ncs(file_path: str) -> bool:
383394
# Compile many files by spreading them across multiple compiler processes
384395
def compile_files(self, working_dir, script_list: list):
385396
# Get compiler config
386-
compiler_cmd = self.settings.get("compiler_cmd")
387-
compiler_args = self.settings.get("compiler_args")
388-
include_path = self.settings.get("include_path")
397+
compiler_cmd = self.get_settings_value("compiler_cmd")
398+
compiler_args = self.get_settings_value("compiler_args")
399+
include_path = self.get_settings_value("include_path")
389400
include_args = []
390401
for inc in include_path:
391402
include_args.extend(["-i", inc])

‎nwscript_completion.py‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import time
66
import threading
7+
from typing import Any
78
from .nwscript_doc_fixes import get_doc_fix
89

910
def plugin_loaded():
@@ -180,6 +181,16 @@ def __init__(self):
180181
# directory => set() of include-only files
181182
self.include_completions = None
182183

184+
def get_settings_value(self, key: str) -> Any:
185+
proj = sublime.active_window().project_data()
186+
for k in ("settings", "nwscript", key):
187+
if proj is not None:
188+
proj = proj.get(k)
189+
if proj is not None:
190+
return proj
191+
192+
return self.settings.get(key)
193+
183194
def on_query_completions(self, view: sublime.View, prefix: str, locations: (str, str, (int, int))) -> list:
184195
if not view.scope_name(locations[0]).startswith("source.nss"):
185196
return
@@ -213,7 +224,7 @@ def on_query_completions(self, view: sublime.View, prefix: str, locations: (str,
213224
)
214225

215226
# Show include error if looking for symbol completions
216-
if len(include_errors) > 0 and self.settings.get("enable_missing_include_popup") is True:
227+
if len(include_errors) > 0 and self.get_settings_value("enable_missing_include_popup") is True:
217228
text = "<br>".join(include_errors)
218229
sublime.active_window().active_view().show_popup(
219230
'<html style="background-color: color(var(--background) blend(red 75%));"><p>' + text + '</p></html>',
@@ -229,13 +240,13 @@ def on_modified(self, view: sublime.View) -> None:
229240
if not view.scope_name(point).startswith("source.nss"):
230241
return
231242

232-
if self.settings.get("enable_doc_popup") is False:
243+
if self.get_settings_value("enable_doc_popup") is False:
233244
return
234245

235246
module_path, file_path = self.get_opened_file_paths(view)
236247
file_data = view.substr(sublime.Region(0, view.size()))
237248

238-
if self.settings.get("parse_on_modified") is True:
249+
if self.get_settings_value("parse_on_modified") is True:
239250
self.parse_script_tree(module_path, file_path, file_data)
240251

241252
if view.substr(point) in ['(', ')'] or point != view.sel()[0].end():
@@ -253,7 +264,7 @@ def on_hover(self, view: sublime.View, point: tuple, hover_zone) -> None:
253264
if not view.scope_name(point).startswith("source.nss"):
254265
return
255266

256-
if self.settings.get("enable_doc_popup") is False:
267+
if self.get_settings_value("enable_doc_popup") is False:
257268
return
258269

259270
# Ignore hover over non selected text
@@ -393,7 +404,7 @@ def find_file_by_resref(self, module_path: str, resref: str) -> str:
393404
path_list = []
394405
if module_path is not None:
395406
path_list.append(module_path)
396-
path_list.extend(self.settings.get("include_path"))
407+
path_list.extend(self.get_settings_value("include_path"))
397408

398409
for path in path_list:
399410
file = os.path.join(path, resref + ".nss")
@@ -514,7 +525,7 @@ def parse_script(self, file_path: str, file_data: str = None) -> None:
514525
doc = Documentation()
515526
doc.signature = ("f", fun_type, fun_name, args)
516527
doc.script_resref = resref
517-
doc.fix = self.settings.get("doc_fixes").get(resref, {}).get(fun_name, None)
528+
doc.fix = self.get_settings_value("doc_fixes").get(resref, {}).get(fun_name, None)
518529
if doc.fix is None:
519530
doc.fix = get_doc_fix(resref, fun_name)
520531

@@ -636,7 +647,7 @@ def worker():
636647
path_list = []
637648
if module_path is not None:
638649
path_list.append(module_path)
639-
path_list.extend(self.settings.get("include_path"))
650+
path_list.extend(self.get_settings_value("include_path"))
640651

641652
for dir_path in path_list:
642653
# Don't go through already parsed folders
@@ -673,7 +684,7 @@ def get_include_completions(self, module_path):
673684
path_list = []
674685
if module_path is not None:
675686
path_list.append(module_path)
676-
path_list.extend(self.settings.get("include_path"))
687+
path_list.extend(self.get_settings_value("include_path"))
677688

678689
ret = []
679690
for path in path_list:

0 commit comments

Comments
 (0)