get global token parsing and docstrings working
This commit is contained in:
parent
f3c6ac488c
commit
1f466a1625
13
src/cache.rs
13
src/cache.rs
|
@ -1,8 +1,8 @@
|
|||
use dashmap::DashMap;
|
||||
use pest::error::Error;
|
||||
use log::info;
|
||||
use tower_lsp::lsp_types::CompletionItem;
|
||||
|
||||
use crate::{parse_global_symbols, parse_skill};
|
||||
use crate::parse_skill;
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
struct Position {
|
||||
|
@ -32,14 +32,9 @@ impl SymbolCache {
|
|||
}
|
||||
|
||||
pub fn update(&self, path: &str) {
|
||||
self.symbols.insert(path.to_owned(), vec![]);
|
||||
let parsed = parse_skill(path);
|
||||
for rule in parsed {
|
||||
match parse_global_symbols(rule) {
|
||||
Ok(_) => {}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
info!("parsed: {:?}", parsed);
|
||||
self.symbols.insert(path.to_owned(), parsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -83,6 +83,13 @@ impl LanguageServer for Backend {
|
|||
Ok(InitializeResult {
|
||||
server_info: None,
|
||||
capabilities: ServerCapabilities {
|
||||
workspace: Some(WorkspaceServerCapabilities {
|
||||
workspace_folders: Some(WorkspaceFoldersServerCapabilities {
|
||||
supported: Some(true),
|
||||
change_notifications: Some(OneOf::Left(true)),
|
||||
}),
|
||||
file_operations: None,
|
||||
}),
|
||||
execute_command_provider: Some(ExecuteCommandOptions {
|
||||
commands: vec!["custom/notification".to_string()],
|
||||
work_done_progress_options: Default::default(),
|
||||
|
@ -134,14 +141,24 @@ impl LanguageServer for Backend {
|
|||
}
|
||||
|
||||
async fn completion(&self, cparams: CompletionParams) -> Result<Option<CompletionResponse>> {
|
||||
let symbols: Vec<CompletionItem> = self
|
||||
.cache
|
||||
.symbols
|
||||
.get_mut(&cparams.text_document_position.text_document.uri.to_string())
|
||||
.unwrap()
|
||||
.to_vec();
|
||||
info!("triggered completion");
|
||||
let path = cparams
|
||||
.text_document_position
|
||||
.text_document
|
||||
.uri
|
||||
.path()
|
||||
.to_string();
|
||||
info!("for: {:?}", path);
|
||||
info!("with: {:?}", self.cache.symbols);
|
||||
let resp = self.cache.symbols.get(&path);
|
||||
info!("returned: {:?}", resp);
|
||||
Ok(Some(CompletionResponse::Array(resp.unwrap().to_vec())))
|
||||
}
|
||||
|
||||
Ok(Some(CompletionResponse::Array(symbols)))
|
||||
async fn did_save(&self, params: DidSaveTextDocumentParams) {
|
||||
let path = params.text_document.uri.path().to_string();
|
||||
info!("updating cahce for {:?}", path);
|
||||
self.cache.update(&path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ number = @{NUMBER+ ~ ("." ~ NUMBER+)? ~ ("e" ~ "-"? ~ NUMBER+)?}
|
|||
bool = {"t" | "nil"}
|
||||
literal = _{string | number | bool}
|
||||
|
||||
COMMENT = _{";" ~ (!NEWLINE ~ ANY)* ~ NEWLINE}
|
||||
COMMENT = {";" ~ (!NEWLINE ~ ANY)* ~ NEWLINE}
|
||||
|
||||
lisp_list = _{ "(" ~ expr* ~ ")" }
|
||||
lazy_list = _{ "'(" ~ expr* ~ ")" }
|
||||
|
|
75
src/skill.rs
75
src/skill.rs
|
@ -1,18 +1,81 @@
|
|||
use log::info;
|
||||
use pest::error::Error;
|
||||
use pest::iterators::Pair;
|
||||
|
||||
use pest::Parser;
|
||||
use std::fs;
|
||||
|
||||
use log::info;
|
||||
use tower_lsp::lsp_types::{
|
||||
lsif::{EdgeDataMultiIn, Item, ItemKind},
|
||||
CompletionItem, CompletionItemKind, CompletionItemLabelDetails, Documentation, MarkupContent,
|
||||
MarkupKind,
|
||||
};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[grammar = "skill.pest"]
|
||||
pub struct SkillParser;
|
||||
|
||||
pub fn parse_skill(path: &str) -> Vec<Pair<Rule>> {
|
||||
let parsed = SkillParser::parse(Rule::skill, path);
|
||||
info!("{:?}", parsed);
|
||||
vec![]
|
||||
fn recurse_pairs<'a>(
|
||||
ps: Pair<Rule>,
|
||||
catalog: &'a mut Vec<CompletionItem>,
|
||||
last_comment: Option<String>,
|
||||
) -> Option<String> {
|
||||
let mut comment = last_comment;
|
||||
match ps.as_rule() {
|
||||
Rule::skill => {
|
||||
comment = None;
|
||||
for p in ps.into_inner() {
|
||||
comment = recurse_pairs(p, catalog, comment);
|
||||
}
|
||||
}
|
||||
Rule::list => {
|
||||
comment = None;
|
||||
for p in ps.into_inner() {
|
||||
comment = recurse_pairs(p, catalog, comment);
|
||||
}
|
||||
}
|
||||
Rule::COMMENT => {
|
||||
info!("encountered comment: {:?}", ps.as_str());
|
||||
if ps.as_str().starts_with(";;;") {
|
||||
comment = Some(ps.as_str().strip_prefix(";;;").unwrap().trim().to_owned());
|
||||
info!("encountered docstring: {:?}", comment);
|
||||
}
|
||||
}
|
||||
Rule::assign => {
|
||||
let k = ps.into_inner().next().unwrap();
|
||||
|
||||
catalog.push(CompletionItem {
|
||||
label: k.as_str().to_owned(),
|
||||
kind: Some(CompletionItemKind::VARIABLE),
|
||||
detail: match &comment {
|
||||
Some(s) => Some(s.to_owned()),
|
||||
None => None,
|
||||
},
|
||||
label_details: Some(CompletionItemLabelDetails {
|
||||
description: None,
|
||||
detail: Some("global".to_owned()),
|
||||
}),
|
||||
..Default::default()
|
||||
});
|
||||
comment = None;
|
||||
}
|
||||
_ => {
|
||||
comment = None;
|
||||
}
|
||||
}
|
||||
comment
|
||||
}
|
||||
|
||||
pub fn parse_skill(path: &str) -> Vec<CompletionItem> {
|
||||
let content = fs::read_to_string(path).expect("could not read file");
|
||||
let parsed = SkillParser::parse(Rule::skill, &content);
|
||||
let mut ret = vec![];
|
||||
let mut last_comment: Option<String> = None;
|
||||
for pairs in parsed.into_iter() {
|
||||
for pair in pairs.into_iter() {
|
||||
last_comment = recurse_pairs(pair, &mut ret, last_comment)
|
||||
}
|
||||
}
|
||||
ret
|
||||
}
|
||||
pub fn parse_global_symbols(token: Pair<Rule>) -> Result<&str, Error<Rule>> {
|
||||
Ok("")
|
||||
|
|
|
@ -13,7 +13,9 @@ token
|
|||
'(lazy list)
|
||||
cstyle(list with args)
|
||||
|
||||
var = arg1 + arg2 - " A" / 12
|
||||
;;; precursor magnitude as controlvector
|
||||
tap_mag = arg1 + arg2 - " A" / 12
|
||||
var2 = "a"
|
||||
obj->op()
|
||||
|
||||
(let (a (b 3))
|
||||
|
|
Loading…
Reference in New Issue