-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
275 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ko_fi: opa_oz | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: "Build and push new LSP" | ||
|
||
on: | ||
release: | ||
types: [ created ] | ||
|
||
permissions: | ||
contents: write | ||
packages: write | ||
|
||
jobs: | ||
releases-matrix: | ||
name: Release Go Binary | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
goos: [ linux, windows, darwin ] | ||
goarch: [ "386", amd64, arm64 ] | ||
exclude: | ||
- goarch: "386" | ||
goos: darwin | ||
- goarch: arm64 | ||
goos: windows | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: wangyoucao577/go-release-action@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
goversion: "1.22" | ||
goos: ${{ matrix.goos }} | ||
goarch: ${{ matrix.goarch }} | ||
binary_name: "pug-lsp" | ||
ldflags: "-s -w" | ||
extra_files: LICENSE | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pug-lsp | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.PHONY: help | ||
|
||
help: | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
test: ## Run unit tests | ||
@go test ./pkg/utils ./pkg/query ./pkg/html ./pkg/documents | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,48 @@ | ||
## LSP is under heavy development | ||
# pug-lsp: Pug Language Protocol Server | ||
|
||
An implementation of the Language Protocol Server for [Pug.js](https://pugjs.org) | ||
|
||
## Features | ||
|
||
`pug-lsp` aims to provide suggestions for you to edit `.pug` in your editor. | ||
|
||
### Note | ||
|
||
Project is under heavy development. Current functionality can be change in stable release. | ||
|
||
### Tags suggestions | ||
|
||
Auto suggest list of HTML5 tags. | ||
|
||
![tags-suggestions](docs/tags-suggestions.png) | ||
|
||
### Attributes suggestions | ||
|
||
#### Auto suggest common attributes (such as `style`, `class`, `title`) for tags | ||
|
||
![common-attributes](docs/common-attributes.png) | ||
|
||
#### Auto suggest events (such as `onclick`, `onenter`) for tags | ||
|
||
![events-attributes](docs/events-attributes.png) | ||
|
||
#### Auto suggest tag-specific attributes (such as `href` for `a`) | ||
|
||
![special-attributes](docs/special-attributes.png) | ||
|
||
#### `&attributes` snippet | ||
|
||
_Yes, it's [a real feature](https://pugjs.org/language/attributes.html#attributes) of Pug_ | ||
|
||
![attributes-shortcut](docs/attributes-shortcut.png) | ||
|
||
|
||
## Thanks | ||
|
||
- [zealot128/tree-sitter-pug](https://github.com/zealot128/tree-sitter-pug) | ||
|
||
|
||
---- | ||
|
||
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S6S1UZ9P7) | ||
|
||
Stay tuned! (and don't forget to press star!) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package documents_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/opa-oz/pug-lsp/pkg/documents" | ||
"github.com/opa-oz/pug-lsp/pkg/query" | ||
"github.com/stretchr/testify/assert" | ||
protocol "github.com/tliron/glsp/protocol_3_16" | ||
) | ||
|
||
func TestApplyChanges(t *testing.T) { | ||
orig := ` | ||
doctype html | ||
html | ||
body | ||
div | ||
` | ||
newContent := ` | ||
doctype html | ||
html | ||
body | ||
div.my-class#my-div | ||
p | ||
span My awesome text | ||
` | ||
|
||
doc := documents.Document{} | ||
|
||
changes := []interface{}{ | ||
protocol.TextDocumentContentChangeEventWhole{ | ||
Text: orig, | ||
}, | ||
} | ||
|
||
err := doc.ApplyChanges(context.TODO(), changes) | ||
assert.NoError(t, err) | ||
assert.Equal(t, *doc.Content, orig) | ||
assert.NotNil(t, doc.Tree) | ||
|
||
changes = []interface{}{ | ||
protocol.TextDocumentContentChangeEventWhole{ | ||
Text: newContent, | ||
}, | ||
} | ||
err = doc.ApplyChanges(context.TODO(), changes) | ||
assert.NoError(t, err) | ||
assert.Equal(t, *doc.Content, newContent) | ||
assert.NotNil(t, doc.Tree) | ||
} | ||
|
||
func TestPositions(t *testing.T) { | ||
orig := ` | ||
doctype html | ||
html | ||
body | ||
div.my-class#my-div | ||
p | ||
span My awesome text | ||
` | ||
|
||
doc := documents.Document{} | ||
|
||
changes := []interface{}{ | ||
protocol.TextDocumentContentChangeEventWhole{ | ||
Text: orig, | ||
}, | ||
} | ||
|
||
err := doc.ApplyChanges(context.TODO(), changes) | ||
assert.NoError(t, err) | ||
assert.Equal(t, *doc.Content, orig) | ||
assert.NotNil(t, doc.Tree) | ||
|
||
position := protocol.Position{ | ||
Line: 6, | ||
Character: 25, | ||
} | ||
|
||
node := doc.GetAtPosition(&position) | ||
assert.NotNil(t, node) | ||
assert.Equal(t, node.Type(), string(query.ContentNodeType)) // we found "My awesome text" | ||
|
||
node = doc.GetBeforeTrigger(&position) | ||
assert.NotNil(t, node) | ||
assert.Equal(t, node.Type(), string(query.TagNameNode)) // we found tag_name=span before "My awesome text" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package query_test | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/opa-oz/pug-lsp/pkg/pug" | ||
"github.com/opa-oz/pug-lsp/pkg/query" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAllIncludes(t *testing.T) { | ||
content := ` | ||
include mixins/logo | ||
include head | ||
include footer | ||
doctype html | ||
html | ||
div | ||
` | ||
testTree, err := pug.GetParsedTreeFromString(context.TODO(), content) | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, testTree) | ||
|
||
includes, err := query.FindAllIncludes(testTree) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, len(*includes), 3) | ||
|
||
var includesFiles []string | ||
|
||
for _, strRange := range *includes { | ||
original := strings.Trim(content[strRange.StartPos:strRange.EndPos], " ") | ||
|
||
includesFiles = append(includesFiles, original) | ||
} | ||
|
||
assert.Equal(t, includesFiles, []string{ | ||
"mixins/logo", "head", "footer", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters