Skip to content
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

Flexible grammar installer #54

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
567438c
added functionality to add grammars
Oct 26, 2023
2038954
use local queries
Oct 26, 2023
765f350
added queries path
Oct 26, 2023
9251830
mkdir queries path
Oct 26, 2023
a335aeb
removed
Oct 26, 2023
5c7499a
minor formatting
Oct 26, 2023
793e30b
removed
Oct 26, 2023
3f4d231
added end
Oct 26, 2023
3a9e679
fixed typo
Oct 26, 2023
7aa5302
removed installer dependency
Oct 26, 2023
a2a3f83
fixed add grammars
Oct 26, 2023
8d620b9
simplified configuration to one single function
Oct 26, 2023
a6ac76b
updated doc
Oct 26, 2023
664a69b
added missing require
Oct 26, 2023
c9366e4
adding language to map only after installing
Oct 26, 2023
bbe676e
refactor!: refactored code and used camel case for all functions
Oct 27, 2023
fad305f
style: reformatted using lua lsp
Oct 27, 2023
300df49
refactor!: refactoring of installation and configuration of grammars …
Oct 27, 2023
0ef96db
refactor: moved localPath from `highlights` to `util`
Oct 27, 2023
ca43b2a
feat: added defaults, installFromUrl and defaults queries support
Oct 27, 2023
b9ab1e3
refactor: moved installation functions to `installer`
Oct 27, 2023
66b7d09
style: formatted using lua lsp
Oct 27, 2023
3b2ed63
refactor: added localPath to util module
Oct 27, 2023
ddb480f
feat: added back default queries
Oct 27, 2023
960a5c0
fix: installation of default queries now works fine
Oct 27, 2023
b6b4502
docs: updated README with default languages and new module structure
Oct 27, 2023
7264bea
feat: added command status to check health of grammars
Oct 27, 2023
0bc6e9b
refactor: moved `exists` and `isDir` to util
Oct 27, 2023
f4d6970
feat: added table of installed grammars
Oct 27, 2023
a7d2756
Revert "minor formatting"
Oct 29, 2023
5076eee
fix: inconsistency in the readme solved
Oct 29, 2023
15bdef3
style: using single quotes everywhere
Oct 29, 2023
698fdd0
feat: added default git repos and the possibility to chose between pr…
Oct 29, 2023
a4d566b
doc: updated with latest changes
Oct 29, 2023
3099dd9
refactor: extracted method `installGrammar` from `addGrammar`.
Oct 29, 2023
34b0776
feat: added simple update-all command
Oct 29, 2023
2446f29
feat: added command to update a specific language grammar
Oct 29, 2023
4026229
refactor: extracted method `exec` and `rmDir` from installer to util
Oct 29, 2023
e125b80
feat: added command clean to remove unused parsers and queries
Oct 29, 2023
5b29cbf
fix: clean uses the table `languages.grammars` to enstablish used gra…
Oct 29, 2023
11f351f
Update README.md
Mandarancio Jan 25, 2024
4037982
Update README.md
Mandarancio Jan 25, 2024
eb36b1e
fix: quiet log for installer
Jan 25, 2024
a7295ca
fix: removed `d` as it is no longer precompiled
Jan 25, 2024
774a081
feat: using tables for filenames and extensions
Jan 25, 2024
5b0fd55
feat: update documentation with new extensions/filenames configuration
Jan 25, 2024
b3bdffe
fix: fixed iteration in table
Jan 25, 2024
7acffda
fix: `evergreen:status` work with extensions and filenames table
Jan 25, 2024
199a327
fix: removed `D` lang from default grammars
Jan 25, 2024
a086f92
fix: using system utilities to remove directories
Jan 26, 2024
9054fe5
feat: simplify readme
Feb 7, 2024
230c829
feat: added function to replace `~` with home path
Feb 12, 2024
2e74455
fix: installGrammarFromPath and installQueries improved and fixed
Feb 12, 2024
bc19546
doc: updated to fix error in example
Feb 12, 2024
041d2c7
feat: using file patterns with regex instead of extensions and filenames
Feb 16, 2024
af1f741
merged
Aug 5, 2024
d68ab5c
Merge branch 'Evergreen-lxl-master'
Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Mandarancio marked this conversation as resolved.
Show resolved Hide resolved
80 changes: 64 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,69 @@ It is work in progress, but functions well.
| ![](before.png) | ![](after.png) |

# Supported Languages
- [x] [C][tree-sitter-c]
- [x] [C++][tree-sitter-cpp]
- [ ] CSS
- [x] [D][tree-sitter-d]
- [x] [Diff][tree-sitter-diff]
- [x] [Go][tree-sitter-go]
- [x] [go.mod][tree-sitter-go-mod]
- [ ] HTML
- [x] [Javascript/JSX][tree-sitter-javascript]
- [x] [Julia][tree-sitter-julia]
- [x] [Lua][tree-sitter-lua]
- [x] [Rust][tree-sitter-rust]
- [x] [Zig][tree-sitter-zig]

If you want more languages supported, open an issue.

Any language supported by `tree-sitter` should (in theory) be supported as well.

It is possible to use grammar installed locally or directly from their git repository. Additionally
it is possible to specify where to find the queries of the language as well as use sub path for projects
containing more then one language.

## Locally installed grammars

To add a grammar to lite-xl simply add the following configuration to your `init.lua` script:

```lua
local langs = require "plugins.evergreen.languages"

langs.add_grammar {
path = "YOUR GRAMMAR LOCAL PATH",
lang = "LANGUAGE NAME",
extensions = "FILE EXTENSIONS", -- optional for extension name based
filename = "FILE NAME", -- optional for file name based
queries = "QUERIES SUB PATH", -- optional sub path of grammar queries, default = 'queries'
}
```

## From git repository
To add a grammar directly from a git repository add this to your `init.lua` scripts:

```lua
local langs = require "plugins.evergreen.languages"
langs.add_grammar {
git = "GIT REPO",
lang = "LANGUAGE NAME",
extensions = "FILE EXTENSIONS", -- optional for extension name based
filename = "FILE NAME", -- optional for file name based
queries = "QUERIES SUB PATH", -- optional sub path of grammar queries, default = 'queries'
subpath = "GRAMMAR SUB PATH", -- optional sub path if grammar is nested, default = nil
revision = "SPECIFIC GIT REVISION", -- optional version of the code to clone
}
```

## Example

```lua
local languages = require "plugins.evergreen.languages"

languages.add_grammar {
path = "~/.grammars/tree-sitter-epics/epics-db",
lang = "epics_db",
extensions = "db,vdb",
}

languages.add_grammar {
git = "https://github.com/tree-sitter/tree-sitter-cpp.git",
lang = "cpp",
extensions = "cpp,hpp,cc",
}

languages.add_grammar {
git = "https://github.com/tree-sitter/tree-sitter-c.git",
lang = "c",
extensions = "c,h",
}

```
Mandarancio marked this conversation as resolved.
Show resolved Hide resolved

# Requirements
- Lite XL 2.1+ or [Pragtical](https://github.com/pragtical/pragtical)
Expand All @@ -39,7 +87,7 @@ If you want more languages supported, open an issue.
Evergreen can be easily installed with [Miq](https://github.com/TorchedSammy/Miq) by
adding this to your plugin declaration:
```lua
{'TorchedSammy/Evergreen.lxl'},
{'TorchedSammy/Evergreen.lxl'}
```

## Manually
Expand Down
2 changes: 2 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ local M = {
}

M.parserLocation = util.join {M.dataDir, 'parsers'}
M.queryLocation = util.join {M.dataDir, 'queries'}

return M

4 changes: 3 additions & 1 deletion highlights.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local parser = require 'plugins.evergreen.parser'
local languages = require 'plugins.evergreen.languages'
local config = require 'plugins.evergreen.config'

local M = {}

Expand All @@ -9,7 +10,7 @@ local function localPath()
end

function M.query(ftype)
local ff = io.open(string.format('%s/queries/%s/highlights.scm', localPath(), ftype))
local ff = io.open(string.format('%s/%s/highlights.scm', config.queryLocation, ftype))
if not ff then
return ""
end
Expand Down Expand Up @@ -86,3 +87,4 @@ function M.init(doc)
end

return M

3 changes: 2 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ end

system.mkdir(config.dataDir)
system.mkdir(config.parserLocation)
system.mkdir(config.queryLocation)

appendPaths {
util.join {config.dataDir, '?' .. util.soname},
Expand Down Expand Up @@ -71,7 +72,6 @@ local Highlight = require 'core.doc.highlighter'
local parser = require 'plugins.evergreen.parser'
local highlights = require 'plugins.evergreen.highlights'
require 'plugins.evergreen.style'
require 'plugins.evergreen.installer'

--- @class core.doc
--- @field treesit boolean
Expand Down Expand Up @@ -255,3 +255,4 @@ command.add('core.docview!', {
end
end
})

101 changes: 0 additions & 101 deletions installer.lua

This file was deleted.

Loading