Skip to content

Commit

Permalink
v0.1.8 version
Browse files Browse the repository at this point in the history
  • Loading branch information
uros-5 committed Apr 5, 2024
1 parent 359df16 commit 5f8e38b
Show file tree
Hide file tree
Showing 28 changed files with 449 additions and 304 deletions.
31 changes: 13 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ resolver = "2"
members = [
"jinja-lsp-queries",
"jinja-lsp",
"example"
]

[profile.dev]
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<img src="https://raw.githubusercontent.com/uros-5/jinja-lsp/main/.github/banner.png" alt="" />
<img src="https://raw.githubusercontent.com/uros-5/jinja-lsp/main/.github/banner.png" alt="banner" />

jinja-lsp enhances minijinja development experience by providing Helix/Nvim users with advanced features such as autocomplete, syntax highlighting, hover, goto definition, code actions and linting.

<div align="center">
<a href="https://crates.io/crates/jinja-lsp"><img alt="crates.io" src="https://img.shields.io/crates/v/jinja-lsp.svg?style=for-the-badge&color=fdbb39&logo=rust" height="20"></a>
<a href="https://marketplace.visualstudio.com/items?itemName=urosmrkobrada.jinja-lsp"><img alt="visualstudio.com" src="https://vsmarketplacebadges.dev/version/urosmrkobrada.jinja-lsp.svg?color=007ACC" height="20"></a>
</div>

## Installation

```sh
Expand Down Expand Up @@ -80,4 +85,4 @@ name = "jinja"
language-servers = ["jinja-lsp"]
```

[VSCode support](https://marketplace.visualstudio.com/search?term=jinja-lsp&target=VSCode&category=Other&sortBy=Relevance)
Supported languages: Python, Rust
2 changes: 1 addition & 1 deletion editors/code/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "VSCode part of a language server",
"author": "uros-5",
"license": "MIT",
"version": "0.1.73",
"version": "0.1.80",
"publisher": "uros",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions editors/code/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function activate(context: ExtensionContext) {
// The server is implemented in node
const serverModule = getServer();
if (!serverModule.valid) {
throw new Error(serverModule.name);
throw new Error(serverModule.name);
}

let config: Record<string, any> = JSON.parse(
Expand All @@ -30,7 +30,7 @@ export function activate(context: ExtensionContext) {
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { command: serverModule.name},
run: { command: serverModule.name },
debug: {
command: serverModule.name,
args: [],
Expand All @@ -40,11 +40,11 @@ export function activate(context: ExtensionContext) {
// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: 'file', language: 'jinja-html' }, { scheme: 'file', language: 'rust' }],
documentSelector: [{ scheme: 'file', language: 'jinja-html' }, { scheme: 'file', language: 'rust' }, { scheme: 'file', language: 'python' }],
initializationOptions: config,
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.{jinja, rs}')
fileEvents: workspace.createFileSystemWatcher('**/.{jinja, rs, python}')
}
};

Expand Down
4 changes: 2 additions & 2 deletions editors/code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jinja-lsp",
"description": "jinja-lsp",
"license": "MIT",
"version": "0.1.73",
"version": "0.1.80",
"repository": {
"url": "https://github.com/uros-5/jinja-lsp"
},
Expand All @@ -17,14 +17,17 @@
"multi-root ready",
"jinja",
"minijinja",
"rust"
"rust",
"jinja-lsp",
"python"
],
"engines": {
"vscode": "^1.75.0"
},
"activationEvents": [
"onLanguage:jinja-html",
"onLanguage:rust"
"onLanguage:rust",
"onLanguage:python"
],
"main": "./client/out/extension",
"contributes": {
Expand All @@ -47,7 +50,8 @@
"jinja-lsp.lang": {
"type": "string",
"enum": [
"rust"
"rust",
"python"
],
"default": "rust",
"description": "Language that is used on backend"
Expand Down
3 changes: 2 additions & 1 deletion jinja-lsp-queries/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jinja-lsp-queries"
version = "0.1.71"
version = "0.1.80"
edition = "2021"
description = "TreeSitter queries for jinja-lsp"
license = "MIT"
Expand All @@ -11,4 +11,5 @@ tree-sitter-jinja2 = "0.0.6"
tree-sitter-rust = "0.20.4"
tower-lsp = { version = "0.20.0", features = ["proposed"] }
ropey = "1.5.0"
tree-sitter-python = "=0.20.4"

20 changes: 5 additions & 15 deletions jinja-lsp-queries/src/lsp_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn search_errors(
file_name: &String,
templates: &String,
lang_type: LangType,
) -> Option<Vec<Diagnostic>> {
) -> Option<Vec<(JinjaDiagnostic, Identifier)>> {
let mut diagnostics = vec![];
match lang_type {
LangType::Template => {
Expand Down Expand Up @@ -70,11 +70,7 @@ pub fn search_errors(
}
}
if to_warn {
let diagnostic = create_diagnostic(
&Identifier::from(&object),
err_type.severity(),
err_type.to_string(),
);
let diagnostic = (err_type, Identifier::from(&object));
diagnostics.push(diagnostic);
}
}
Expand All @@ -90,15 +86,13 @@ pub fn search_errors(
for i in id_templates {
let err_type = JinjaDiagnostic::TemplateNotFound;
if i.name.is_empty() {
let diagnostic =
create_diagnostic(i, err_type.severity(), err_type.to_string());
let diagnostic = (err_type, i.to_owned());
diagnostics.push(diagnostic);
} else {
let path = format!("{templates}/{}", i.name);
if let Err(err) = std::fs::canonicalize(path) {
if err.kind() == ErrorKind::NotFound {
let diagnostic =
create_diagnostic(i, err_type.severity(), err_type.to_string());
let diagnostic = (err_type, i.to_owned());
diagnostics.push(diagnostic);
}
}
Expand All @@ -115,11 +109,7 @@ pub fn search_errors(
let path = format!("{templates}/{}", template.name);
if let Err(err) = std::fs::canonicalize(path) {
if err.kind() == ErrorKind::NotFound {
let diagnostic = create_diagnostic(
template,
DiagnosticSeverity::WARNING,
"Template not found".to_string(),
);
let diagnostic = (JinjaDiagnostic::TemplateNotFound, template.to_owned());
diagnostics.push(diagnostic);
}
}
Expand Down
7 changes: 7 additions & 0 deletions jinja-lsp-queries/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ impl Parsers {
LangType::Backend => self.backend.parse(text, old_tree),
}
}

pub fn update_backend(&mut self, lang: &str) {
if lang == "python" {
self.backend = Parser::new();
let _ = self.backend.set_language(tree_sitter_python::language());
}
}
}

impl Default for Parsers {
Expand Down
1 change: 0 additions & 1 deletion jinja-lsp-queries/src/search/definition2.rs

This file was deleted.

39 changes: 0 additions & 39 deletions jinja-lsp-queries/src/search/jinja_state.rs

This file was deleted.

2 changes: 0 additions & 2 deletions jinja-lsp-queries/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use tree_sitter::Point;
use self::objects::JinjaObject;

pub mod definition;
pub mod jinja_state;
pub mod objects;
pub mod queries;
pub mod rust_identifiers;
pub mod rust_state;
pub mod rust_template_completion;
pub mod snippets_completion;
pub mod templates;
Expand Down
4 changes: 3 additions & 1 deletion jinja-lsp-queries/src/search/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,6 @@ pub enum CompletionType {
Snippets { range: Range },
}

static VALID_IDENTIFIERS: [&str; 6] = ["loop", "true", "false", "not", "as", "module"];
static VALID_IDENTIFIERS: [&str; 8] = [
"loop", "true", "false", "not", "as", "module", "super", "url_for",
];
Loading

0 comments on commit 5f8e38b

Please sign in to comment.