Skip to content

feat(#44): support env var specification#47

Merged
xiaoshihou514 merged 3 commits intonvimdev:mainfrom
barrettruth:env
Aug 12, 2023
Merged

feat(#44): support env var specification#47
xiaoshihou514 merged 3 commits intonvimdev:mainfrom
barrettruth:env

Conversation

@barrettruth
Copy link
Copy Markdown
Contributor

support env var spec like so:

ft('cpp'):fmt('clang-format'):env({ A = 'b' })

maintains existing env vars (does not override other than what's specified)

Comment thread lua/guard/filetype.lua Outdated
return self
end

function tbl:env(...)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env just receive a param env table<string, string> . if vim.tbl_count(env) == 0 return then we can se tool.env == env add a validate first by using vim.validate for param env.

Copy link
Copy Markdown
Contributor Author

@barrettruth barrettruth Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempted to resolve in next commit. Do the table keys and values also need to be validates like so?

    for k, v in pairs(env) do
      vim.validate({
        k = { k, 'string' },
        v = { v, 'string' }
      })
    end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that we cannot set tool.env = env because uv.os_environ() returns the environment like:

{ key = val }

and uv.spawn() needs the env like:

{ 'key=val' }

Comment thread lua/guard/filetype.lua
end
tool.env = {}
env = vim.tbl_extend('force', vim.uv.os_environ(), env or {})
for k, v in pairs(env) do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm why we need these codes. just tool.env = env ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say that above:

Also note that we cannot set tool.env = env because uv.os_environ() returns the environment like:

{ key = val }
and uv.spawn() needs the env like:

{ 'key=val' }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's make sense but do we need extend os_environ ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I believe applying an env override removes all environment variables from the uv.spawn() process or something.

As evidence, it just doesn't work with spawning certain processes (like prettierd, for example) and breaks. Keeping uv.os_environ() fixes it. null-ls also does it.

Comment thread lua/guard/filetype.lua Outdated
Co-authored-by: Raphael <glephunter@gmail.com>
@xiaoshihou514 xiaoshihou514 merged commit c70cd92 into nvimdev:main Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants