Skip to content

Commit ce5417d

Browse files
authored
Merge pull request #4 from antonk52/f/comments-in-classnames-hovers
support comments in hover lookup
2 parents 4ece1af + c5f32f4 commit ce5417d

File tree

8 files changed

+218
-67
lines changed

8 files changed

+218
-67
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
plugins: ['@typescript-eslint', 'prettier'],
99
parser: '@typescript-eslint/parser',
1010
rules: {
11-
indent: ['error', 4, {SwitchCase: 1}],
11+
indent: 0,
1212
'@typescript-eslint/no-var-requires': 0,
1313
'@typescript-eslint/no-unused-vars': 'error',
1414
'@typescript-eslint/explicit-module-boundary-types': 0,

README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Language server for `autocompletion` and `go-to-definition` functionality for cs
44

55
<p align="center"><img src="https://user-images.githubusercontent.com/5817809/76164832-0adaf600-6163-11ea-8c8e-548b7aeb1213.gif"></p>
66

7+
Features:
8+
9+
- **definition** jumps to class name under cursor.
10+
- **implementation** (works the same as definition).
11+
- **hover** provides comments before the class name with direct declarations within the class name.
12+
713
The supported languages are `css`(postcss), `sass` and `scss`. `styl` files are parsed as regular `css`.
814

915
## Installation
@@ -18,33 +24,29 @@ See if your editor supports language servers or if there is a plugin to add supp
1824

1925
### Neovim
2026

21-
Example uses [`nvim-lspconfig`](https://github.com/neovim/lspconfig)
27+
Example uses [`nvim-lspconfig`](https://github.com/neovim/nvim-lspconfig)
28+
29+
```lua
30+
require'lspconfig'.cssmodules_ls.setup {
31+
-- provide your on_attach to bind keymappings
32+
on_attach = custom_on_attach,
33+
-- optionally
34+
init_options = {
35+
camelCase = 'dashes',
36+
},
37+
}
38+
```
39+
40+
**Known issue**: if you have multiple LSP that provide hover and go-to-definition support, there can be races(example typescript and cssmodules-language-server work simultaneously). As a workaround you can disable **definition** in favor of **implementation** to avoid conflicting with typescript's go-to-definition.
2241

2342
```lua
24-
local configs = require'lspconfig/configs'
25-
26-
if not configs.cssmodules then
27-
configs.cssmodules = {
28-
default_config = {
29-
cmd = {'cssmodules-language-server'},
30-
filetypes = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact'},
31-
init_options = {
32-
camelCase = 'dashes',
33-
},
34-
root_dir = require('lspconfig.util').root_pattern('package.json')
35-
},
36-
docs = {
37-
description = 'TODO description',
38-
default_config = {
39-
root_dir = '[[root_pattern("package.json")]]'
40-
}
41-
}
42-
}
43-
end
44-
45-
configs.cssmodules.setup {}
46-
-- or
47-
-- configs.cssmodules.setup {on_attach = custom_on_attach}
43+
require'lspconfig'.cssmodules_ls.setup {
44+
on_attach = function (client)
45+
-- avoid accepting `go-to-definition` responses from this LSP
46+
client.resolved_capabilities.goto_definition = false
47+
custom_on_attach(client)
48+
end,
49+
}
4850
```
4951

5052
### [coc.nvim](https://github.com/neoclide/coc.nvim)

src/DefinitionProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ export class CSSModulesDefinitionProvider {
8383
return {
8484
contents: {
8585
language: 'css',
86-
value: stringiyClassname(field, node.declarations),
86+
value: stringiyClassname(
87+
field,
88+
node.declarations,
89+
node.comments,
90+
),
8791
},
8892
};
8993
}

0 commit comments

Comments
 (0)