Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tower-lsp = "0.20.0"
tower = { version = "0.4", features = ["util"] }
dashmap = "6.1.0"
ropey = "1.6.1"
tx3-lang = "0.7.2"
tx3-lang = "0.11.0"
pest = "2.7.15"
miette = "7.5.0"
serde_json = "1.0.140"
Expand Down
8 changes: 6 additions & 2 deletions src/ast_to_svg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::Write;
use tx3_lang::ast::Identifier;
use tx3_lang::ast::InputBlockField;
use tx3_lang::ast::OutputBlockField;
use tx3_lang::ast::Program;
Expand Down Expand Up @@ -145,9 +146,11 @@ fn get_outputs(tx: &TxDef) -> Vec<Parameter> {
.enumerate()
.map(|(i, output)| {
let name = output
.name
.clone()
.unwrap_or_else(|| format!("output {}", i + 1));
.name
.unwrap_or(Identifier::new(format!("output {}", i + 1)))
.value;

let party = output.fields.iter().find_map(|f| {
if let OutputBlockField::To(address_expr) = f {
address_expr
Expand All @@ -158,6 +161,7 @@ fn get_outputs(tx: &TxDef) -> Vec<Parameter> {
None
}
});

Parameter { name, party }
})
.collect()
Expand Down
27 changes: 18 additions & 9 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde_json::Value;
use tower_lsp::{jsonrpc::Result, lsp_types::*, LanguageServer};
use tx3_lang::ast::Identifier;

use crate::{
cmds, position_to_offset, span_contains, span_to_lsp_range,
Expand Down Expand Up @@ -189,7 +190,7 @@ impl LanguageServer for Context {

for output in &tx.outputs {
if let Some(output_name) = &output.name {
if output_name == &identifier.value {
if output_name == identifier {
return Ok(Some(GotoDefinitionResponse::Scalar(Location {
uri: uri.clone(),
range: span_to_lsp_range(document.value(), &output.span),
Expand Down Expand Up @@ -307,14 +308,17 @@ impl LanguageServer for Context {
}
}

for output in &tx.outputs {
for (i, output) in tx.outputs.iter().enumerate() {
if span_contains(&output.span, offset) {
let default_output = "output".to_string();
let default_output = Identifier::new(format!("output {}", i + 1));
let name = output.name.as_ref().unwrap_or(&default_output);
return Ok(Some(Hover {
contents: HoverContents::Markup(MarkupContent {
kind: MarkupKind::Markdown,
value: format!("**Output**: `{}`\n\nTransaction output.", name),
value: format!(
"**Output**: `{}`\n\nTransaction output.",
name.value
),
}),
range: Some(span_to_lsp_range(document.value(), &output.span)),
}));
Expand Down Expand Up @@ -360,10 +364,11 @@ impl LanguageServer for Context {

if !tx.outputs.is_empty() {
hover_text.push_str("**Outputs**:\n");
for output in &tx.outputs {
let default_output = "output".to_string();
for (i, output) in tx.outputs.iter().enumerate() {
let default_output = Identifier::new(format!("output {}", i + 1));

let name = output.name.as_ref().unwrap_or(&default_output);
hover_text.push_str(&format!("- `{}`\n", name));
hover_text.push_str(&format!("- `{}`\n", name.value));
}
}

Expand Down Expand Up @@ -456,9 +461,13 @@ impl LanguageServer for Context {
));
}

for output in tx.outputs {
for (i, output) in tx.outputs.iter().enumerate() {
let default_output = Identifier::new(format!("output {}", i + 1));

let name = output.name.as_ref().unwrap_or(&default_output);

children.push(make_symbol(
output.name.unwrap_or_else(|| { "output" }.to_string()),
name.value.clone(),
"Output".to_string(),
SymbolKind::OBJECT,
span_to_lsp_range(document.value(), &output.span),
Expand Down
35 changes: 7 additions & 28 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ fn visit_tx_def<'a>(tx: &'a tx3_lang::ast::TxDef, offset: usize) -> Option<Symbo
return Some(sym);
}
}
for burn in &tx.burns {
if let Some(sym) = visit_mint_block(burn, offset) {
return Some(sym);
}
}
for ref_block in &tx.references {
if let Some(sym) = visit_reference_block(ref_block, offset) {
return Some(sym);
Expand All @@ -83,11 +88,6 @@ fn visit_tx_def<'a>(tx: &'a tx3_lang::ast::TxDef, offset: usize) -> Option<Symbo
return Some(sym);
}
}
if let Some(burn) = &tx.burn {
if let Some(sym) = visit_burn_block(burn, offset) {
return Some(sym);
}
}
if let Some(metadata) = &tx.metadata {
if let Some(sym) = visit_metadata_block(metadata, offset) {
return Some(sym);
Expand Down Expand Up @@ -305,27 +305,6 @@ fn visit_validity_block<'a>(
None
}

fn visit_burn_block<'a>(
bb: &'a tx3_lang::ast::BurnBlock,
offset: usize,
) -> Option<SymbolAtOffset<'a>> {
for field in &bb.fields {
match field {
tx3_lang::ast::MintBlockField::Amount(expr) => {
if let Some(sym) = visit_data_expr(expr, offset) {
return Some(sym);
}
}
tx3_lang::ast::MintBlockField::Redeemer(expr) => {
if let Some(sym) = visit_data_expr(expr, offset) {
return Some(sym);
}
}
}
}
None
}

fn visit_metadata_block<'a>(
_mb: &'a tx3_lang::ast::MetadataBlock,
_offset: usize,
Expand Down Expand Up @@ -451,11 +430,11 @@ fn visit_policy_field<'a>(
}

fn visit_address_expr<'a>(
expr: &'a tx3_lang::ast::AddressExpr,
expr: &'a tx3_lang::ast::DataExpr,
offset: usize,
) -> Option<SymbolAtOffset<'a>> {
match expr {
tx3_lang::ast::AddressExpr::Identifier(id) => visit_identifier(id, offset),
tx3_lang::ast::DataExpr::Identifier(id) => visit_identifier(id, offset),
_ => None,
}
}
Expand Down