-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yaml-language-server settting yaml.schemaStore.url not working #1207
Comments
Can you please paste the example yaml that you're using? If you take a look over at redhat-developer/yaml-language-server#307 and https://github.com/redhat-developer/yaml-language-server/issues/211you'll see a lot of discussion about the peculiar behavior of the server when it comes to k8s. This took some effort so I hope it will work for you nvim_lsp[name].setup {
--cmd = cmd,
on_attach = on_attach,
settings = {
yaml = {
trace = {
server = "verbose"
},
schemas = {
kubernetes = "/*.yaml"
},
schemaDownload = { enable = true },
validate = true,
}
},
} I then tested it with this which gives a "Property not allowed" error and in the lsp.log I see it actually validated against v1.20.5 which indicates success! {
jsonrpc = "2.0",
method = "textDocument/publishDiagnostics",
params = {
diagnostics = {
{
code = 0,
data = {
schemaUri = { "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.20.5-standalone-strict/_definitions.json" }
},
message = "Property containers is not allowed.",
range = { end = { character = 12, line = 8 }, start = {character = 2, line = 8 } },
severity = 1,
source = "yaml-schema: https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.20.5-standalone-strict/_definitions.json"
}
},
uri = "file:///tmp/backend-service.k8s.yaml"
}
} |
@kylo252 Thank you. |
As I mentioned earlier, that seems like an internal issue with the language server, you can see the hard-coded value here: So I guess you can just build the server yourself, or some are talking about overriding it with an environment variable, maybe that's a thing(?). And you can see in redhat-developer/yaml-language-server#211 that the devs aren't terribly invested in making this easier. This could also be of interest for you if there's some port that works with lspconfig: https://github.com/Azure/vscode-kubernetes-tools |
This seems resolved? Can one of you document this in yaml language server and file a PR? |
Not resolved. I still don't know how to use k8s v1.22.
Thanks,
; Long
…On Wed, 8 Sep, 2021, 1:05 AM Michael Lingelbach, ***@***.***> wrote:
This seems resolved? Can one of you document this in yaml language server
and file a PR?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1207 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGZVWWLCGESJHJL3HJHEN3UAZSOVANCNFSM5DCMJ2MQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Reading the yamlls code, it seems like you can do something like: require('lspconfig').yamlls.setup{
settings = { yaml = { schemas = { kubernetes = 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.22.1-standalone/all.json'}}}
} As kylo mentioned, this isn't really an lspconfig thing, but more a "how to send the right settings to the server", so you may need to read through the upstream documentation. |
Yeah this snippet is supposed to work, but it's either not reliable or straight-up broken. I do believe that in essence it's 100% a language-server problem, even by the dev admission, as you can see in the tickets that I linked. |
But it seems like this works for the user on the referenced issue no? |
I tried. Does not work. I am hospitalized. I will explain in detail after I
am able to.
Thanks,
; Long
…On Wed, 8 Sep, 2021, 11:41 PM Michael Lingelbach, ***@***.***> wrote:
But it seems like this works for the user no?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1207 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGZVWV6AD7XCKW74UVK4DTUA6RMPANCNFSM5DCMJ2MQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Sorry to hear that. Get better soon! -- @mjlbach, it didn't work for me as I said. Maybe I needed to turn off the Do you think it would be possible to port the linter from https://github.com/Azure/vscode-kubernetes-tools ? |
I would just file an upstream issue. I don't use yamlls, so I won't
wdym port the linter? port the linter to what? Do you mean extract a linter out of a vscode and wrap it into its own language server? I have 0 idea. |
My opinion is that Michael has assessed the problem accurately.
If I just configure dot yaml files as kubernetes schema, with all else
being default, then linter and autocompletion work perfectly. You can try
yourself.
To force the yaml language server to use a schemastore of choice is also
not possible. If you see the link I pasted earlier about how a schemastore
of choice can be bruteforced into the yaml server, that is the only current
solution. But that was with COC. Now have to look how to do that in
lspconfig.
Thanks,
; Long
…On Thu, 9 Sep, 2021, 1:13 PM Michael Lingelbach, ***@***.***> wrote:
Maybe I needed to turn off the schemaDownload, but I don't see how that
should affect it, i.e. it's unreliable.
I would just file an upstream issue. I don't use yamlls, so I won't
Do you think it would be possible to port the linter from
https://github.com/Azure/vscode-kubernetes-tools ?
wdym port the linter? port the linter to what? Do you mean extract a
linter out of a vscode and wrap it into its own language server? I have 0
idea.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1207 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGZVWRDGRP3ZTMM4HJ4O4TUBBQTFANCNFSM5DCMJ2MQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@longwuyuan were you able to resolve the issue? If you can provide an exact reproduction (our minimal init.lua modified to use the schema you wanted, a yaml file you would expect to work) I will look at it. |
My lua file
|
Hi @longwuyuan, hope you are feeling better :) I don't see yamlls anywhere in that lua file, were you having another issue? I updated the documentation for yamlls that should cover the custom schemas (tested on a couple files myself and it seemed to work as expected). |
ah ok... i will have to go through the tests again. apologies if i confused you.
If this is correct, I will do the needful and check the docs and change settings and test This involves another issue , not related to this project. The schema for kubernetes 1.22 is not available on the web as well. One has to use the script provided, to generate the kubernetes 1.22 schema |
This should work, try adding the following into a kubernetes yaml (not sure if this is the correct schema): # yaml-language-server: $schema=https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.22.0/deployment-apps-v1.json This modeline should set the kubernetes schema correctly to 1.22, there are other online schema available on that repo here: https://github.com/yannh/kubernetes-json-schema/tree/master/v1.22.0 |
oh, this is so helpful. thanks tons. I will try now |
If you check server_configurations.md you can see the other way, which would be affiliating that URL with a filesystem path relative to resolved root of the project which is the tricky part, since that's dynamic and depends on your project structure (that's a yamlls quirk, which I guess makes sense since it would not be compatible on different systems otherwise). I personally think the modeline is easier haha, since you don't have to worry about relative anything. |
I am a little lost now. have to get my bearings. This is my current init.vim
Now, I have to check where to put your sugested config |
You put my comment in the yaml file itself (if you can edit it), see |
alternatively require('lspconfig').yamlls.setup {
on_attach = on_attach,
settings = {
yaml = {
schemas = {
["https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.22.0/deployment-apps-v1.json"] = "/*"
}
}
},
} |
Something wonderful is being observed. Now next problem is autocompletion. You can see my init.vim above. If you already know of any tips to get autocompletion, I will be grateful. |
You can try copy/pasting that into the config you pasted above (the first one) which I believe is also the example config I wrote https://github.com/nvim-lua/kickstart.nvim That includes autocompletion/snippet support out of the box |
Apologies, I don't understand. Next I mentioned I am unable to gt autocomplete with cntrl+space. Likely I have forgotten and need to check key mappings in my init.vim I pasted above. I was hoping you know how to enable autocomplete for kubernetes yaml. THen I see you sugested I copy/paste. I already copy/pasted just the one line that begins with a brace. That solved the schema problem. Do I need to copy/paste something else to solve the autocompletion problem. Thanks tons again. |
That, to me, does not sound like autocompletion but completion for which you could use the built-in omnifunc. There's no difference anymore with the built-in client between completion sources, the difference is now in the interface. Built-in, neovim has manually triggered completion via omnifunc (), which you could map to ctrl-space. If you want auto-completion, where the completion menu automatically pops up, you'd want to install a completion plugin like https://github.com/hrsh7th/nvim-cmp which is documented in our wiki. For manually triggered completion (what I think you want):Add this somewhere, add it within your on_attach callbac if you only want it to take effect when the language server starts
You can then trigger completion for any running language server (including yamlls which I verified) with (control-x control-o) which you can remap to ctrl-space. For autocompletion:Specifically you'd want to install these four plugins (nvim-cmp uses a modular approach as opposed to monolithic): and add this https://github.com/nvim-lua/kickstart.nvim/blob/61bd292f2a3ac15ee641b6524586a5ec1aa25df4/init.lua#L275-L320 to your config. |
Thanks so much again. I am checking this |
I chose autocompletion so installed the 4 plugins and put the config in init.vim. But yo have helped so much and autocompletion is documented and this issue was not for autocompletion. Just that I expected i expected nvim-cmp to work for yaml, just like it does for golang. Please suggest if we should drop this conversation here as this is not the original topic of this already closed issue. Thanks tons. |
With the kickstart.nvim config, with only the following modification (and yamlls installed of course): diff --git a/init.lua b/init.lua
index 5f3e8ea..c1ed0c8 100644
--- a/init.lua
+++ b/init.lua
@@ -224,7 +224,7 @@ local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- Enable the following language servers
-local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' }
+local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver', 'yamlls' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach, If I open the following yaml file: action.yaml # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json If I add a new line and type |
:-( this is not working ; @mjlbach , where am i making a mistake :-( |
That's not what I sent you :) The pattern is schema: filepattern, like:
what you have above is schema: schema. You proably don't ever want to explicitly write "kubernetes" on the left, as that uses their built-in schemas (which you don't want to use), and you always want the right to be a file pattern. |
This comment has been minimized.
This comment has been minimized.
I am copy/pasting my init.vim as well the error below ;
|
That is not a valid lua table :) |
Ooops, don't know what I was thinking 🤦♂️ |
@longwuyuan that's a bit too long for me to go through 😅 I'd recommend starting with the kickstart.nvim config (which I'm almost certain works), and gradually modifying it to see where things break. |
ok. will do that now |
@mjlbach , i see the same error with minimimal_init.lua for yamlls ;
|
What version of neovim are you on? You should be on at least the 0.5.1 release |
ok. big apology. Looks like I am on 0.5.0
I will try to change now and check |
No worries, there were some bugfixes to the client that you are running into that were fixed in the 0.5.1 release (0.6 is coming out in a few weeks). Generally lspconfig will support the nightly + last stable version (I'm going to start semver after the 0.6 release) |
ok. different behaviour with 5.1. Attacin log file here ;
|
You didn't say what the different behavior is :) The log file looks fine. |
oh sorry .. not bonkers at all. to validate all objects .. i should put all.json there |
No worries :) I know nothing about k8s but there are a ton of different schemas under that 1.22 subfolder, maybe it's not the deployment-apps one you need |
true. this is super fantastic. I just put the modeline in my yaml file and it works wonders. your help and your work is the motivation to use nvim. thanks tons. Not sure if this is right place to ask, but after all the youtube videos and blogs, is there a authoritative list of plugins or a authoritative init.lua that is designed for practical use anywhere ? I mean for serious work, what are the plugns and related configs I need to add. nvim-cmp seems like one requirement. Beyond that there is so much talk about gitgutter, airline etc |
You are welcome! As for your question, it depends. That's why I created kickstart.nvim/try.nvim, to at least give people a place to start. There are also "frameworks" like lunarvim, nvchad, et. al. Lunarvim appears reasonably popular. I am personally a KISS/DIY person so I stick to things I write myself haha |
Thanks tons. Same here in terms of KISS/DIY. But I am not a developer level skilled user. The biggest problem right now is closing unused files. The shortcuts and :bd (buffer delete) commands close and exit the editor nvim. There seems no way to keep nvim open and just close some files. |
For those type questions I would ask on the matrix. I think at least the yaml-language-server issue is mostly resolved :) |
yes... not ostly ... i think fully and satisfactory resolved as no more a mystery. thanks tons. |
nvim --version
:% nvim --version
NVIM v0.5.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az242-526
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "
/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"
Run :checkhealth for more info
latest as of today as i did a PlugUpdate
yaml-language-server
I have a workaround with coc on vim https://octetz.com/docs/2020/2020-01-06-vim-k8s-yaml-support/
Not tried as he setting is unique
Yes
Debian
How to reproduce the problem from neovim startup
Actual behaviour
Expected behaviour
Minimal init.vim or init.lua and code sample
Health check
LSP log
The text was updated successfully, but these errors were encountered: