Skip to content

Commit 749b192

Browse files
committed
check remote mixin content type when downloading
1 parent e7ef7ee commit 749b192

3 files changed

Lines changed: 22 additions & 26 deletions

File tree

config/config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ func (c *Config) readMixins(mixins []*Mixin) error {
282282

283283
for _, mixin := range mixins {
284284
if err := c.readMixin(mixin); err != nil {
285-
// TODO: check if error is correct, concise and for humans
286-
return err
285+
return fmt.Errorf("failed to read remote mixin config '%s': %w", mixin.Remote.URL, err)
287286
}
288287
}
289288

config/config/mixin.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ import (
1212
"strings"
1313
"time"
1414

15+
"github.com/lets-cli/lets/set"
1516
"github.com/lets-cli/lets/util"
1617
)
1718

19+
var allowedContentTypes = set.NewSet(
20+
"text/plain",
21+
"text/yaml",
22+
"text/x-yaml",
23+
"application/yaml",
24+
"application/x-yaml",
25+
)
26+
1827
type Mixins []*Mixin
1928

2029
type Mixin struct {
@@ -110,6 +119,11 @@ func (rm *RemoteMixin) download() ([]byte, error) {
110119
return nil, fmt.Errorf("network error: %s", resp.Status)
111120
}
112121

122+
contentType := resp.Header.Get("Content-Type")
123+
if !allowedContentTypes.Contains(contentType) {
124+
return nil, fmt.Errorf("unsupported content type: %s", contentType)
125+
}
126+
113127
data, err := io.ReadAll(resp.Body)
114128
if err != nil {
115129
return nil, fmt.Errorf("failed to read response: %w", err)

docs/docs/ide_support.md

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,18 @@ vim.filetype.add({
6262
})
6363
```
6464

65-
2. In your `neovim/nvim-lspconfig` servers configuration:
65+
2. Define `lets_ls` lsp config
6666

67-
In order for `nvim-lspconfig` to recognize `lets lsp` we must define config for `lets_ls` (lets_ls is just a conventional name because we are not officially added to `neovim/nvim-lspconfig`)
67+
Requires `neovim >= 0.11.2`
6868

6969
```lua
70-
require("lspconfig.configs").lets_ls = {
71-
default_config = {
72-
cmd = {
73-
"lets self lsp",
74-
},
75-
filetypes = { "yaml.lets" },
76-
root_dir = util.root_pattern("lets.yaml"),
77-
settings = {},
78-
},
70+
vim.lsp.config.lets_ls = {
71+
cmd = { "lets", "self", "lsp" },
72+
filetypes = { "yaml.lets" },
73+
root_markers = { "lets.yaml" },
7974
}
80-
```
81-
82-
3. And then enable lets_ls in then servers section:
8375

84-
```lua
85-
return {
86-
"neovim/nvim-lspconfig",
87-
opts = {
88-
servers = {
89-
lets_ls = {},
90-
pyright = {}, -- pyright here just as hint to where we should add lets_ls
91-
},
92-
},
93-
}
76+
vim.lsp.enable("lets_ls")
9477
```
9578

9679
### JSON Schema

0 commit comments

Comments
 (0)