Skip to content

Commit

Permalink
Merge pull request #24 from uros-5/fix-completion
Browse files Browse the repository at this point in the history
Fix completion
  • Loading branch information
uros-5 authored Aug 1, 2024
2 parents 31dd797 + ffa3622 commit 8db9d70
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 26 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:
- main
- fix-completion
tags-ignore:
- '**'
paths-ignore:
Expand Down
2 changes: 1 addition & 1 deletion jinja-lsp-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class NodejsLspFiles {
/** Actions can come from unsaved context. */
addGlobalContext(uri: string, actions?: Array<Action> | undefined | null): void
deleteAll(filename: string): void
addOne(id: number, filename: string, content: string, line: number, ext: string): Array<JsIdentifier>
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): Array<JsCompletionItem> | null
Expand Down
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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"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.11",
"version": "0.0.13",
"main": "index.js",
"types": "index.d.ts",
"napi": {
Expand Down
17 changes: 15 additions & 2 deletions jinja-lsp-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,18 @@ impl NodejsLspFiles {
&mut self,
id: u32,
filename: String,
content: String,
mut content: String,
line: u32,
ext: String,
col: Option<u32>,
// is_json: bool,
) -> Vec<JsIdentifier> {
let col = col.unwrap_or(0);
let mut space_before = String::new();
for _ in 0..col {
space_before.push_str(" ");
}
content = format!("{space_before}{content}");
let mut all_identifiers = vec![];
let params: DidOpenTextDocumentParams = DidOpenTextDocumentParams {
text_document: TextDocumentItem::new(
Expand Down Expand Up @@ -309,6 +317,7 @@ impl NodejsLspFiles {
mut position: JsPosition,
) -> Option<Vec<JsCompletionItem>> {
position.line -= line;
let original_uri = &format!("{filename}");
let uri = Url::parse(&format!("file:///home/{filename}.{id}.jinja")).unwrap();
let position = Position::new(position.line, position.character);
let params: CompletionParams = CompletionParams {
Expand Down Expand Up @@ -349,7 +358,11 @@ impl NodejsLspFiles {
}

CompletionType::Identifier => {
if let Some(variables) = self.lsp_files.read_variables(&uri, position, None) {
if let Some(variables) =
self
.lsp_files
.read_variables(&uri, position, None, Some(original_uri.to_string()))
{
let mut ret = vec![];
for item in variables {
ret.push(JsCompletionItem {
Expand Down
11 changes: 7 additions & 4 deletions jinja-lsp/src/channels/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub fn lsp_task(
}
CompletionType::Identifier => {
if let Some(variables) =
lsp_data.read_variables(&uri, position, None)
lsp_data.read_variables(&uri, position, None, None)
{
items = Some(CompletionResponse::Array(variables));
}
Expand Down Expand Up @@ -220,9 +220,12 @@ pub fn lsp_task(
}
}
CompletionType::IncompleteIdentifier { name, range } => {
if let Some(variables) =
lsp_data.read_variables(&uri, position, Some((name, range)))
{
if let Some(variables) = lsp_data.read_variables(
&uri,
position,
Some((name, range)),
None,
) {
items = Some(CompletionResponse::Array(variables));
}
}
Expand Down
6 changes: 6 additions & 0 deletions jinja-lsp/src/lsp_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ impl LspFiles {
uri: &Url,
position: Position,
starting: Option<(String, Range)>,
nodejs_uri: Option<String>,
) -> Option<Vec<CompletionItem>> {
let mut items = vec![];
let start = position.line as usize;
Expand Down Expand Up @@ -674,7 +675,12 @@ impl LspFiles {
// }
}
}
let is_nodejs = nodejs_uri.is_some();
let uri = nodejs_uri.unwrap_or(String::new());
for file in self.variables.iter() {
if is_nodejs && file.0 != &uri {
continue;
}
for variable in file.1 {
if variable.identifier_type == IdentifierType::BackendVariable {
items.push(CompletionItem {
Expand Down

0 comments on commit 8db9d70

Please sign in to comment.