Skip to content

Commit

Permalink
Support "variable" variables (http_name, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
pappasam committed Feb 24, 2021
1 parent 4177852 commit 385f1ea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.4.0

### Added

- Variable completion for variables names appended with `_name`, like `http`. These refer to http headers based on the characters.

### Changed

- Words that aren't symbols no longer hover. You now need your cursor over an actual symbol to get hover.

## 0.3.0

### Added
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ In your vimrc, I recommend putting in the following lines to ensure variables co
augroup custom_nginx
autocmd!
autocmd FileType nginx set iskeyword+=$
augroup end
augroup custom_coc_additional_keyword_characters
autocmd!
autocmd FileType nginx
\ let b:coc_additional_keywords = ['.', '/', '"', '$', '-']
autocmd FileType nginx let b:coc_additional_keywords = ['$']
augroup end
```

Expand Down
8 changes: 6 additions & 2 deletions nginx_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def completion(
else None
)


@SERVER.feature(HOVER)
def hover(
server: LanguageServer, params: TextDocumentPositionParams
Expand All @@ -81,6 +80,9 @@ def hover(
word = pygls_utils.word_at_position(document, params.position)
line = nginxconf.find(parsed, params.position.line)

# append "_name" to beginning of word
word_name = word.rsplit("_", maxsplit=1)[0] + "_name"

if not line:
return None
contexts = line.contexts if line.contexts else ["main"]
Expand All @@ -92,7 +94,9 @@ def hover(
if word not in possibilities:
if line.line != params.position.line:
return None
found = possibilities[line.directive]
if word_name not in possibilities:
return None
found = possibilities[word_name]
else:
found = possibilities[word]
contents = MarkupContent(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ line_length = 79

[tool.poetry]
name = "nginx-language-server"
version = "0.3.0"
version = "0.4.0"
description = "A language server for nginx.conf"
authors = ["Sam Roeca <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 385f1ea

Please sign in to comment.