Skip to content

Commit

Permalink
feat(*): v0.3.2
Browse files Browse the repository at this point in the history
- fix(vscode): update checker is now enabled by default, and some of its logic
  has been modified and fixed. It also supports cancellation of the install task
- fix(vscode): give defaults to all config options
- fix(server): fix crash with code actions
  • Loading branch information
Jamalam360 committed Apr 29, 2023
1 parent 4fd597c commit 160999a
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 154 deletions.
33 changes: 23 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ All notable changes will be documented in this file.

<!-- Check [Keep a Changelog](https://keepachangelog.com/) for recommendations on how to structure this file. -->

## v0.3.2

- fix(vscode): update checker is now enabled by default, and some of its logic
has been modified and fixed. It also supports cancellation of the install task
- fix(vscode): give defaults to all config options
- fix(server): fix crash with code actions

## v0.3.1

- revert(server): revert performance marks temporarily, while they are refactored into a more generic crate
- revert(server): revert performance marks temporarily, while they are
refactored into a more generic crate

## v0.3.0

Expand All @@ -23,32 +31,37 @@ All notable changes will be documented in this file.

## v0.2.1

- fix(vscode): scan both stdout and stderr of Cargo commands, fixes some issues with installation flow
- fix(vscode): scan both stdout and stderr of Cargo commands, fixes some issues
with installation flow
- feat(*): documentation, issue templates
- feat(sublime): begin publishing a sublime text package
- fix(server, vscode): server now hot-reloads config updates more reliably
- fix(server, vscode): bump problematic dependencies (love the JS ecosystem...a CVE a day keeps the doctor away)
- fix(server, vscode): server now hot-reloads config updates more reliably
- fix(server, vscode): bump problematic dependencies (love the JS ecosystem...a
CVE a day keeps the doctor away)
- feat(server): add rule inlining code action
- feat(server): ignore unused rule name analysis if there is only one unused rule (hack fix)
- feat(server): ignore unused rule name analysis if there is only one unused
rule (hack fix)

## v0.2.0

- feat(*): port to tower lsp
- This will allow the usage of this LS by other IDEs.
- The vscode extension will prompt you to download the server.
- Other IDEs will have to have the LS installed via `cargo install`.
- This will allow the usage of this LS by other IDEs.
- The vscode extension will prompt you to download the server.
- Other IDEs will have to have the LS installed via `cargo install`.
- feat(*): add configuration options
- feat(server, #6): diagnostic for unused rules
- feat(server, #7): show rule docs (`///`) on hover
- fix(server, #8): solve issue relating to 0 vs 1 indexing causing diagnostics to occur at the wrong locations
- fix(server, #8): solve issue relating to 0 vs 1 indexing causing diagnostics
to occur at the wrong locations
- feat(server): add a version checker
- feat(readme, #2): update readme and add demo gif
- feat(ci, #4): automatically populate changelog
- fix(ci): lint all rust code

## v0.1.2

- feat: upgrade pest v2.5.6, pest-fmt v0.2.3. See [Release Notes](https://github.com/pest-parser/pest/releases/tag/v2.5.6).
- feat: upgrade pest v2.5.6, pest-fmt v0.2.3. See
[Release Notes](https://github.com/pest-parser/pest/releases/tag/v2.5.6).
- fix(server): solve issue relating to 0 vs 1 indexing.
- feat(server): suggest user-defined rule names in intellisense.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion language-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pest-language-server"
version = "0.3.1"
version = "0.3.2"
authors = ["Jamalam <[email protected]>"]
description = "A language server for Pest."
edition = "2021"
Expand Down
242 changes: 124 additions & 118 deletions language-server/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ impl PestLanguageServerImpl {
.await;

if self.config.check_for_updates {
self.client
.log_message(MessageType::INFO, format!("Checking for updates..."))
.await;

if let Some(new_version) = check_for_updates().await {
self.client
.show_message(
Expand Down Expand Up @@ -338,136 +342,138 @@ impl PestLanguageServerImpl {
let name_range = line.get_word_range_at_idx(rule_name_start_idx);
let rule_name = &str_range(line, &name_range);

let ra = self
.get_rule_analysis(&text_document.uri, rule_name)
.expect("should not be called on a builtin with no rule analysis");

let mut selected_token = None;
if let Some(ra) = self.get_rule_analysis(&text_document.uri, rule_name) {
let mut selected_token = None;

for (token, location) in ra.tokens.iter() {
if range_contains(&location.range, &range) {
selected_token = Some((token, location));
break;
for (token, location) in ra.tokens.iter() {
if range_contains(&location.range, &range) {
selected_token = Some((token, location));
break;
}
}
}

if let Some((extracted_token, location)) = selected_token {
//TODO: Replace with something more robust, it's horrible
let extracted_token_identifier =
match parser::parse(parser::Rule::node, extracted_token) {
Ok(mut node) => {
let mut next = node.next().unwrap();

loop {
match next.as_rule() {
parser::Rule::terminal => {
break next
.into_inner()
.find(|r| r.as_rule() == parser::Rule::identifier);
}
parser::Rule::identifier => {
break Some(next);
}
parser::Rule::string => {
break Some(next);
}
parser::Rule::opening_paren => {
node = node.next().unwrap().into_inner();
let next_opt = node
.find(|r| r.as_rule() == parser::Rule::term)
.unwrap()
.into_inner()
.find(|r| r.as_rule() == parser::Rule::node);

if let Some(new_next) = next_opt {
next = new_next;
} else {
break None;
if let Some((extracted_token, location)) = selected_token {
//TODO: Replace with something more robust, it's horrible
let extracted_token_identifier =
match parser::parse(parser::Rule::node, extracted_token) {
Ok(mut node) => {
let mut next = node.next().unwrap();

loop {
match next.as_rule() {
parser::Rule::terminal => {
break next.into_inner().find(|r| {
r.as_rule() == parser::Rule::identifier
});
}
}
_ => unreachable!(
"unexpected rule in node: {:?}",
next.as_rule()
),
};
parser::Rule::identifier => {
break Some(next);
}
parser::Rule::string => {
break Some(next);
}
parser::Rule::opening_paren => {
node = node.next().unwrap().into_inner();
let next_opt = node
.find(|r| r.as_rule() == parser::Rule::term)
.unwrap()
.into_inner()
.find(|r| r.as_rule() == parser::Rule::node);

if let Some(new_next) = next_opt {
next = new_next;
} else {
break None;
}
}
_ => unreachable!(
"unexpected rule in node: {:?}",
next.as_rule()
),
};
}
.map(|p| p.as_str())
}
.map(|p| p.as_str())
Err(_) => None,
}
Err(_) => None,
}
.unwrap_or("");

if self
.get_rule_analysis(&text_document.uri, extracted_token_identifier)
.is_some()
|| BUILTINS.contains(&extracted_token_identifier)
|| extracted_token.starts_with('\"')
{
let mut rule_name_number = 0;
let extracted_rule_name = loop {
rule_name_number += 1;
let extracted_rule_name = format!("{}_{}", rule_name, rule_name_number);
if self
.get_rule_analysis(&text_document.uri, &extracted_rule_name)
.is_none()
{
break extracted_rule_name;
}
};

let extracted_rule = format!(
"{} = {{ {} }}",
extracted_rule_name.trim(),
extracted_token.trim(),
);

let mut edits = Vec::new();

edits.push(TextEdit {
range: Range {
start: Position {
line: location.range.end.line + 1,
character: 0,
},
end: Position {
line: location.range.end.line + 1,
character: 0,
.unwrap_or("");

if self
.get_rule_analysis(&text_document.uri, extracted_token_identifier)
.is_some()
|| BUILTINS.contains(&extracted_token_identifier)
|| extracted_token.starts_with('\"')
{
let mut rule_name_number = 0;
let extracted_rule_name = loop {
rule_name_number += 1;
let extracted_rule_name =
format!("{}_{}", rule_name, rule_name_number);
if self
.get_rule_analysis(&text_document.uri, &extracted_rule_name)
.is_none()
{
break extracted_rule_name;
}
};

let extracted_rule = format!(
"{} = {{ {} }}",
extracted_rule_name.trim(),
extracted_token.trim(),
);

let mut edits = Vec::new();

edits.push(TextEdit {
range: Range {
start: Position {
line: location.range.end.line + 1,
character: 0,
},
end: Position {
line: location.range.end.line + 1,
character: 0,
},
},
},
new_text: format!("{}\n", extracted_rule),
});

let mut changes = HashMap::new();
changes.insert(text_document.uri.clone(), edits);

for (url, analysis) in self.analyses.iter() {
for (_, ra) in analysis.rules.iter() {
if let Some(ra) = ra {
for (token, location) in ra.tokens.iter() {
if token == extracted_token {
changes
.entry(url.clone())
.or_insert_with(Vec::new)
.push(TextEdit {
range: location.range,
new_text: format!("{} ", extracted_rule_name),
});
new_text: format!("{}\n", extracted_rule),
});

let mut changes = HashMap::new();
changes.insert(text_document.uri.clone(), edits);

for (url, analysis) in self.analyses.iter() {
for (_, ra) in analysis.rules.iter() {
if let Some(ra) = ra {
for (token, location) in ra.tokens.iter() {
if token == extracted_token {
changes
.entry(url.clone())
.or_insert_with(Vec::new)
.push(TextEdit {
range: location.range,
new_text: format!(
"{} ",
extracted_rule_name
),
});
}
}
}
}
}
}

actions.push(CodeActionOrCommand::CodeAction(CodeAction {
title: "Extract into new rule".to_owned(),
kind: Some(CodeActionKind::REFACTOR_EXTRACT),
edit: Some(WorkspaceEdit {
changes: Some(changes),
document_changes: None,
change_annotations: None,
}),
..Default::default()
}));
actions.push(CodeActionOrCommand::CodeAction(CodeAction {
title: "Extract into new rule".to_owned(),
kind: Some(CodeActionKind::REFACTOR_EXTRACT),
edit: Some(WorkspaceEdit {
changes: Some(changes),
document_changes: None,
change_annotations: None,
}),
..Default::default()
}));
}
}
}
}
Expand Down
Loading

0 comments on commit 160999a

Please sign in to comment.