Skip to content

Commit

Permalink
Merge pull request #17 from uros-5/example
Browse files Browse the repository at this point in the history
added Python example
  • Loading branch information
uros-5 authored May 13, 2024
2 parents ae2b2f8 + ba3a762 commit 8d17914
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,48 @@ name = "jinja"
language-servers = ["jinja-lsp"]
```

Neovim configuration

```lua
vim.filetype.add {
extension = {
jinja = 'jinja',
jinja2 = 'jinja',
j2 = 'jinja',
},
}

-- if you want to debug
vim.lsp.set_log_level("debug")

local nvim_lsp = require('lspconfig')
local configs = require('lspconfig.configs')

if not configs.jinja_lsp then
configs.jinja_lsp = {
default_config = {
name = "jinja-lsp",
cmd = { 'path_to_lsp_or_command' },
filetypes = { 'jinja', 'rust' },
root_dir = function(fname)
return "."
--return nvim_lsp.util.find_git_ancestor(fname)
end,
init_options = {
templates = './templates',
backend = { './src' },
lang = "rust"
},
},
}
end
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
nvim_lsp.jinja_lsp.setup {
capabilities = capabilities
}
nvim_lsp.jinja_lsp.setup {
}
```


Supported languages: Python, Rust
11 changes: 11 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# python generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# venv
.venv
venv
1 change: 1 addition & 0 deletions example/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.13
5 changes: 5 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```bash
# from base directory(jinja-lsp)
cd example
git init .
```
29 changes: 29 additions & 0 deletions example/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[project]
name = "example"
version = "0.1.0"
description = "Simple jinja-lsp example for Python"
authors = [
{ name = "uros-5"}
]
dependencies = [
"jinja2>=3.1.4",
]
readme = "README.md"
requires-python = ">= 3.10"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = []

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.wheel]
packages = ["src"]

[tool.pyright]
extraPaths = ["example/.venv/lib/python3.10/site-packages"]
14 changes: 14 additions & 0 deletions example/requirements-dev.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
jinja2==3.1.4
# via example
markupsafe==2.1.5
# via jinja2
14 changes: 14 additions & 0 deletions example/requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# generated by rye
# use `rye lock` or `rye sync` to update this lockfile
#
# last locked with the following flags:
# pre: false
# features: []
# all-features: false
# with-sources: false

-e file:.
jinja2==3.1.4
# via example
markupsafe==2.1.5
# via jinja2
18 changes: 18 additions & 0 deletions example/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from jinja2 import Environment


def main():
jinja_env = Environment()

template = jinja_env.get_template("account.jinja")
template.render(
first_name="John",
last_name="Doe",
email="[email protected]",
phone_number="(123) 456-7890",
street="123 Main St",
city="Dallas",
header_info="This is some information about the user.",
)

jinja_env.globals["PROJECT_NAME"] = "example"

0 comments on commit 8d17914

Please sign in to comment.