Skip to content

Commit

Permalink
0.0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
uros-5 committed Sep 20, 2024
1 parent 5e6998b commit aa6882d
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:
'on':
push:
branches:
- ignore-end-expression
- extending-link-hint-literal
tags-ignore:
- '**'
paths-ignore:
Expand Down
4 changes: 3 additions & 1 deletion jinja-lsp-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ export class NodejsLspFiles {
constructor()
/** Actions can come from unsaved context. */
addLinkHints(uri: string, actions?: Array<Action> | undefined | null): void
saveLinkHint(actions?: Array<Action> | undefined | null, hint?: string | undefined | null): void
removeTempLinkHint(hint?: string | undefined | null): void
deleteAll(filename: string): void
addOne(id: number, filename: string, content: string, line: number, ext: string, col?: number | undefined | null): Array<JsIdentifier>
getVariables(id: string, line: number): Array<JsIdentifier> | null
hover(id: number, filename: string, line: number, position: JsPosition): JsHover | null
complete(id: number, filename: string, line: number, position: JsPosition, linkHints?: string | undefined | null): Array<JsCompletionItem> | null
complete(id: number, filename: string, line: number, position: JsPosition): Array<JsCompletionItem> | null
gotoDefinition(id: number, filename: string, line: number, position: JsPosition): Array<JsLocation> | null
}
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/android-arm-eabi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-android-arm-eabi",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"android"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/android-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-android-arm64",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"android"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-darwin-arm64",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/darwin-universal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-darwin-universal",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/freebsd-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-freebsd-x64",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"freebsd"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/linux-arm-gnueabihf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-linux-arm-gnueabihf",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/linux-arm-musleabihf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-linux-arm-musleabihf",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-linux-arm64-gnu",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-linux-arm64-musl",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/linux-riscv64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-linux-riscv64-gnu",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-linux-x64-gnu",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-linux-x64-musl",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-win32-arm64-msvc",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/win32-ia32-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-win32-ia32-msvc",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions-win32-x64-msvc",
"version": "0.0.20",
"version": "0.0.21",
"os": [
"win32"
],
Expand Down
4 changes: 2 additions & 2 deletions jinja-lsp-nodejs/package-lock.json

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

2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jinja-lsp/functions",
"version": "0.0.20",
"version": "0.0.21",
"main": "index.js",
"types": "index.d.ts",
"napi": {
Expand Down
65 changes: 52 additions & 13 deletions jinja-lsp-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,36 @@ impl NodejsLspFiles {
}
}

#[napi]
pub fn save_link_hint(&mut self, actions: Option<Vec<Action>>, hint: Option<String>) {
let hint = hint.unwrap_or("temp".to_string());
if let Some(actions) = actions {
let mut identifiers = vec![];
let mut action_objects = vec![];
for action in &actions {
let mut identifier = Identifier::new(&action.name, Point::new(0, 0), Point::new(0, 0));
identifier.identifier_type = IdentifierType::BackendVariable;
identifiers.push(identifier);
let action = ActionObject::from(action);
action_objects.push(action);
}
self.action_objects.insert(hint.to_string(), action_objects);
self
.lsp_files
.variables
.insert(hint.to_string(), identifiers);
self.actions.insert(hint.to_string(), actions);
}
}

#[napi]
pub fn remove_temp_link_hint(&mut self, hint: Option<String>) {
let hint = hint.unwrap_or("temp".to_string());
self.lsp_files.variables.remove(&hint);
self.actions.remove(&hint);
self.action_objects.remove(&hint);
}

#[napi]
pub fn delete_all(&mut self, filename: String) {
self.lsp_files.delete_documents_with_id(filename);
Expand Down Expand Up @@ -132,7 +162,7 @@ impl NodejsLspFiles {
.lsp_files
.read_objects(Url::parse(&format!("file:///home/{filename}.{id}.{ext}")).unwrap());
if let Some(objects) = objects {
if let Some(global_actions) = self.action_objects.get(&filename.to_string()) {
if let Some(global_actions) = self.action_objects.get("temp") {
for obj in &objects {
let action_object = ActionObject::from(obj);
for global_action in global_actions {
Expand Down Expand Up @@ -160,7 +190,7 @@ impl NodejsLspFiles {
.lsp_files
.read_python_ids(Url::parse(&format!("file:///home/{filename}.{id}.{ext}")).unwrap())
{
if let Some(global_actions) = self.action_objects.get(&filename.to_string()) {
if let Some(global_actions) = self.action_objects.get("temp") {
for obj in &ids {
let action_object = ActionObject::from(obj);
for global_action in global_actions {
Expand Down Expand Up @@ -315,7 +345,6 @@ impl NodejsLspFiles {
filename: String,
line: u32,
mut position: JsPosition,
link_hints: Option<String>,
) -> Option<Vec<JsCompletionItem>> {
position.line -= line;
let original_uri = filename.to_string();
Expand Down Expand Up @@ -359,12 +388,21 @@ impl NodejsLspFiles {
}

CompletionType::Identifier => {
let url = link_hints.unwrap_or(original_uri.to_string());
if let Some(variables) = self
.lsp_files
.read_variables(&uri, position, None, Some(url))
{
let empty = vec![];
let actions = self.actions.get("temp").unwrap_or(&empty);
if let Some(variables) = self.lsp_files.read_variables(&uri, position, None, None) {
let mut ret = vec![];
for item in actions {
ret.push(JsCompletionItem {
completion_type: JsCompletionType::Identifier,
label: item.name.to_string(),
kind: Kind2::VARIABLE,
description: item.description.to_string(),
new_text: None,
insert: None,
replace: None,
});
}
for item in variables {
ret.push(JsCompletionItem {
completion_type: JsCompletionType::Identifier,
Expand All @@ -376,6 +414,7 @@ impl NodejsLspFiles {
replace: None,
});
}

items = Some(ret);
}
}
Expand Down Expand Up @@ -406,10 +445,9 @@ impl NodejsLspFiles {
CompletionType::IncompleteIdentifier { name, mut range } => {
range.start.line += line;
range.end.line += line;
let url = &original_uri.to_string();
let mut ret = vec![];
let variables = self
.lsp_files
.get_variable(name, uri.to_string(), &filename)?;
let variables = self.lsp_files.get_variable(name, url.to_string(), "temp")?;
for variable in variables {
let item = JsCompletionItem {
completion_type: JsCompletionType::Identifier,
Expand Down Expand Up @@ -465,9 +503,8 @@ impl NodejsLspFiles {
}
GotoDefinitionResponse::Array(locations) => {
for mut location in locations {
print!("{}", location.uri);
let uri2 = location.uri.to_string();
if uri2.contains(&filename) {
if uri2.contains("temp") {
location.uri = Url::parse(&uri2).unwrap();
location.range.start.line += line;
location.range.end.line += line;
Expand Down Expand Up @@ -585,12 +622,14 @@ pub struct JsHover {
}

#[napi(object)]
#[derive(Debug)]
pub struct JsRange {
pub start: JsPosition,
pub end: JsPosition,
}

#[napi(object)]
#[derive(Debug)]
pub struct JsLocation {
pub uri: String,
pub range: JsRange,
Expand Down
3 changes: 2 additions & 1 deletion jinja-lsp-queries/src/search/test_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ mod query_tests {
{{ "|" }}
{{ identifier }}
{{}}
{{ identifier }}
{{ identifier }}
"#;
let cases = [
(
Expand Down Expand Up @@ -292,6 +292,7 @@ mod query_tests {
Some((CompletionType::Identifier, false)),
),
(Point::new(11, 19), None),
(Point::new(12, 28), None),
];
for case in cases {
let tree = prepare_jinja_tree(source);
Expand Down

0 comments on commit aa6882d

Please sign in to comment.