From dc2557e3b04c17469a2c3fe6a8deb11399b3ed2f Mon Sep 17 00:00:00 2001 From: misuzu Date: Tue, 28 Dec 2021 19:20:01 +0200 Subject: [PATCH 1/5] Add `direnv clear cache` to command palette --- Default.sublime-commands | 4 ++++ README.md | 1 + direnv.py | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/Default.sublime-commands b/Default.sublime-commands index 0ee9b4c..047b858 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -6,5 +6,9 @@ { "caption": "direnv deny", "command": "direnv_deny" + }, + { + "caption": "direnv clear cache", + "command": "direnv_clear" } ] diff --git a/README.md b/README.md index d544ea1..71cbc2c 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,4 @@ In order to run a command press `(ctrl|cmd)+shift+p` to view the Command Palette * `direnv allow` to allow and load the current .envrc * `direnv deny` to deny and unload the current .envrc +* `direnv clear cache` to clear filesystem cache diff --git a/direnv.py b/direnv.py index 5bcd3a6..11a2ca9 100644 --- a/direnv.py +++ b/direnv.py @@ -176,6 +176,12 @@ def run(self, edit): direnv.push(self.view.file_name()) +class DirenvClear(sublime_plugin.TextCommand): + def run(self, edit): + direnv_cache.clear() + direnv.push(self.view.file_name()) + + def plugin_loaded(): if shutil.which('direnv') is None: sublime.status_message( From c286a24c34cd503ccdb9d4eaf5c01e277c89fa44 Mon Sep 17 00:00:00 2001 From: misuzu Date: Thu, 30 Dec 2021 21:02:30 +0200 Subject: [PATCH 2/5] Minimize amount of time without direnv environment variables --- direnv.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/direnv.py b/direnv.py index 11a2ca9..18bf4dd 100644 --- a/direnv.py +++ b/direnv.py @@ -87,20 +87,22 @@ def _find_envrc_directory(file_name): file_name = os.path.dirname(file_name) def _update_environment(self, file_path): + def rollback_env(): + self._previous_env, previous_env = {}, self._previous_env + for key, value in previous_env.items(): + if value is None: + os.environ.pop(key) + else: + os.environ[key] = value + direnv_path = self._find_envrc_directory(file_path) direnv_path_prev = self._current_path self._current_path = direnv_path - self._previous_env, previous_env = {}, self._previous_env - for key, value in previous_env.items(): - if value is None: - os.environ.pop(key) - else: - os.environ[key] = value - if direnv_path is None: if direnv_path_prev is not None: + rollback_env() sublime.status_message( "direnv: unloaded %s" % direnv_path_prev) return @@ -114,14 +116,17 @@ def _update_environment(self, file_path): direnv_path, dict(os.environ, **environment)) if returncode != 0: - sublime.status_message(stderr) self._current_path = None + rollback_env() + sublime.status_message(stderr) return if stdout: environment = dict(environment, **json.loads(stdout)) self._cache.set(direnv_path, environment) + rollback_env() + for key, value in environment.items(): if key.startswith('DIRENV_') or value is None: continue From 12f6a693e79d102c15911b4e2383a6e4679ee4f9 Mon Sep 17 00:00:00 2001 From: misuzu Date: Sat, 24 Sep 2022 12:11:42 +0300 Subject: [PATCH 3/5] Update README.md --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71cbc2c..4f787b6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# [direnv](https://direnv.net) integration for Sublime Text 3 +# [direnv](https://direnv.net) integration for Sublime Text 3+ -This plugin adds support for direnv to Sublime Text 3. +This plugin adds support for direnv to Sublime Text 3+. ## Prerequisites @@ -25,3 +25,13 @@ In order to run a command press `(ctrl|cmd)+shift+p` to view the Command Palette * `direnv allow` to allow and load the current .envrc * `direnv deny` to deny and unload the current .envrc * `direnv clear cache` to clear filesystem cache + + +## Limitations + +Since ST doesn't have an API to delay the loading of other plugins, +when using nix to declare dependencies for your project, +plugins like LSP-rust-analyzer won't be able to find them. +If you encounter this issue, you can try to open your project directory in ST, +open your `README`, `.envrc` or some other unrelated file and +wait for direnv to load before opening your source code files. From 1707c8432e2cbb4049d361f2e1ce093663698814 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Mon, 22 Apr 2024 15:29:51 +0200 Subject: [PATCH 4/5] Switch to Python 3.8 Otherwise Sublime LSP will not be able to see the environment changes. --- .python-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..cc1923a --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.8 From 20e766ce6b465d5d9c956a9179b5541eaf192e02 Mon Sep 17 00:00:00 2001 From: misuzu Date: Mon, 22 Apr 2024 18:58:38 +0300 Subject: [PATCH 5/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4f787b6..c354c75 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# [direnv](https://direnv.net) integration for Sublime Text 3+ +# [direnv](https://direnv.net) integration for Sublime Text 4 -This plugin adds support for direnv to Sublime Text 3+. +This plugin adds support for direnv to Sublime Text 4. ## Prerequisites