changed variable system
This commit is contained in:
+3
-28
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::lspcom::{get_completion, get_items, request_methods, LspServer, TextDocumentChangeParams};
|
||||||
lspcom::{get_completion, request_methods, LspServer, TextDocumentChangeParams},
|
|
||||||
variable::VariableType,
|
|
||||||
};
|
|
||||||
use lsp_types::*;
|
use lsp_types::*;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
@@ -36,34 +33,12 @@ impl LspServer for Server {
|
|||||||
.documents
|
.documents
|
||||||
.get(params.text_document_position.text_document.uri.as_str())
|
.get(params.text_document_position.text_document.uri.as_str())
|
||||||
.expect("err_textdoc");
|
.expect("err_textdoc");
|
||||||
let items = get_completion(
|
let items: HashMap<String, crate::variable::Variable> = get_completion(
|
||||||
text.clone(),
|
text.clone(),
|
||||||
params.text_document_position.position.line as usize + 1,
|
params.text_document_position.position.line as usize + 1,
|
||||||
params.text_document_position.position.character as usize,
|
params.text_document_position.position.character as usize,
|
||||||
);
|
);
|
||||||
let mut completion_items: Vec<CompletionItem> = Vec::new();
|
CompletionResponse::Array(get_items(items, "".to_string()))
|
||||||
for (name, var) in items {
|
|
||||||
let mut item = CompletionItem::new_simple(name, var.desc);
|
|
||||||
match var.vtype {
|
|
||||||
VariableType::Func => {
|
|
||||||
item.kind = Some(CompletionItemKind::FUNCTION);
|
|
||||||
}
|
|
||||||
VariableType::Var => {
|
|
||||||
item.kind = Some(CompletionItemKind::VARIABLE);
|
|
||||||
}
|
|
||||||
VariableType::Keyword => {
|
|
||||||
item.kind = Some(CompletionItemKind::KEYWORD);
|
|
||||||
}
|
|
||||||
VariableType::Struct => {
|
|
||||||
item.kind = Some(CompletionItemKind::STRUCT);
|
|
||||||
}
|
|
||||||
VariableType::Namespace => {
|
|
||||||
item.kind = Some(CompletionItemKind::MODULE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
completion_items.push(item);
|
|
||||||
}
|
|
||||||
CompletionResponse::Array(completion_items)
|
|
||||||
}
|
}
|
||||||
fn did_change(&mut self, params: TextDocumentChangeParams) {
|
fn did_change(&mut self, params: TextDocumentChangeParams) {
|
||||||
self.documents.insert(params.uri, params.text);
|
self.documents.insert(params.uri, params.text);
|
||||||
|
|||||||
+45
-2
@@ -1,5 +1,11 @@
|
|||||||
use crate::{parser::new_vars, transpiler::Transpiler, variable::Variable};
|
use crate::{
|
||||||
use lsp_types::{CompletionParams, CompletionResponse, InitializeResult};
|
parser::new_vars,
|
||||||
|
transpiler::Transpiler,
|
||||||
|
variable::{Variable, VariableType},
|
||||||
|
};
|
||||||
|
use lsp_types::{
|
||||||
|
CompletionItem, CompletionItemKind, CompletionParams, CompletionResponse, InitializeResult,
|
||||||
|
};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -56,3 +62,40 @@ pub struct TextDocumentChangeParams {
|
|||||||
pub uri: String,
|
pub uri: String,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_items(
|
||||||
|
items: HashMap<String, crate::variable::Variable>,
|
||||||
|
lname: String,
|
||||||
|
) -> Vec<CompletionItem> {
|
||||||
|
let mut completion_items: Vec<CompletionItem> = Vec::new();
|
||||||
|
for (name, var) in items {
|
||||||
|
let mut item = CompletionItem::new_simple(lname.clone() + &name, var.desc);
|
||||||
|
if var.vtype != VariableType::Func {
|
||||||
|
completion_items.extend(get_items(var.params, name + "::").iter().cloned())
|
||||||
|
} else {
|
||||||
|
// item.documentation = Some(Documentation::MarkupContent(MarkupContent {
|
||||||
|
// kind: MarkupKind::Markdown,
|
||||||
|
// value: "Markup".to_string(),
|
||||||
|
// }));
|
||||||
|
}
|
||||||
|
match var.vtype {
|
||||||
|
VariableType::Func => {
|
||||||
|
item.kind = Some(CompletionItemKind::FUNCTION);
|
||||||
|
}
|
||||||
|
VariableType::Var => {
|
||||||
|
item.kind = Some(CompletionItemKind::VARIABLE);
|
||||||
|
}
|
||||||
|
VariableType::Keyword => {
|
||||||
|
item.kind = Some(CompletionItemKind::KEYWORD);
|
||||||
|
}
|
||||||
|
VariableType::Struct => {
|
||||||
|
item.kind = Some(CompletionItemKind::STRUCT);
|
||||||
|
}
|
||||||
|
VariableType::Namespace => {
|
||||||
|
item.kind = Some(CompletionItemKind::MODULE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
completion_items.push(item);
|
||||||
|
}
|
||||||
|
completion_items
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -172,7 +172,7 @@ impl Transpiler {
|
|||||||
.as_str();
|
.as_str();
|
||||||
result += "\n}\n";
|
result += "\n}\n";
|
||||||
let vvars = variables.clone();
|
let vvars = variables.clone();
|
||||||
if let Some(v) = variables.get_mut(&ast.tokens[1].value) {
|
if let Some(v) = variables.get_mut(&ast.tokens[0].value) {
|
||||||
for (name, var) in vars {
|
for (name, var) in vars {
|
||||||
if !(vvars.contains_key(&name)) {
|
if !(vvars.contains_key(&name)) {
|
||||||
v.params.insert(
|
v.params.insert(
|
||||||
|
|||||||
Reference in New Issue
Block a user