Skip to content

Commit

Permalink
Merge pull request #12 from ace-design/mael_update
Browse files Browse the repository at this point in the history
ast and symbol table for the grammar actual + dot completion
  • Loading branch information
AlexandreLachanceGit authored Jul 6, 2023
2 parents 15705f0 + 154fac9 commit 87871b5
Show file tree
Hide file tree
Showing 14 changed files with 3,453 additions and 650 deletions.
554 changes: 333 additions & 221 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions examples/basic.p4
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ parser MyParser(packet_in packet,
out headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
bit<1> test = 819308190;

bit<16> test = TYPE_IPV4;
egressSpec_t test2 = 1;
bit<16> test3 = 0x80;
bit<16> test4 = 0x50;

state start {
transition parse_ethernet;
}
Expand Down Expand Up @@ -87,6 +90,12 @@ control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
control MyIngress(inout headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {

bit<16> test = TYPE_IPV4;
egressSpec_t test2 = 1;
bit<16> test3 = 0x80;
bit<16> test4 = test3.test.t.aa + test + 0x10;

action drop() {
mark_to_drop(standard_metadata);
}
Expand Down Expand Up @@ -151,7 +160,7 @@ control MyComputeChecksum(inout headers hdr, inout metadata meta) {
HashAlgorithm.csum16);
}
}

ad
/*************************************************************************
*********************** D E P A R S E R *******************************
*************************************************************************/
Expand Down
60 changes: 60 additions & 0 deletions examples/test.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// This P4 file contains only a preamble, it is not meant to be used on its own.

#ifndef _COMMON_CONFIGP4
#define _COMMON_CONFIGP4

#undef TARGET_PSA
#undef TARGET_V1

#include <core.p4>

#ifdef TARGET_TOFINO
#if TARGET_TOFINO == 2
#include <t2na.p4>
#else
#include <tna.p4>
#endif
#else // x86: might be PSA or v1 model, select here
// #define USE_PSA 1
#ifdef USE_PSA
#include <psa.p4>
#define TARGET_PSA 1
#else
#include <v1model.p4>
#define TARGET_V1 1
#endif
#endif

#include "common/headers.p4"
#include "common/util.p4"

#ifdef TARGET_V1
struct mac_learn_digest {
bit<48> src_addr;
PortId_t ingress_port;
}

struct arp_digest {
bit<32> ip; // destination (or nexthop)
bit<48> mac; // own MAC address to be used as SHA in ARP request
}
#else
struct mac_learn_digest_data {
bit<48> src_addr;
PortId_t ingress_port;
}

struct arp_digest_data {
bit<32> ip; // destination (or nexthop)
bit<48> mac; // own MAC address to be used as SHA in ARP request
}

#endif

struct ppv_digest_t {
bit<32> vql4s;
bit<32> vqcl;
bit<48> ts;
}

#endif // COMMON_CONFIG
96 changes: 60 additions & 36 deletions src/features/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,68 @@ impl CompletionBuilder {

pub fn get_list(
position: Position,
source_code: &str,
query: &Arc<Mutex<impl SymbolTableQuery>>,
) -> Option<Vec<CompletionItem>> {
let symbols: Symbols = query.lock().unwrap().get_symbols_at_pos(position)?;
fn default(
position: Position,
query: &Arc<Mutex<impl SymbolTableQuery>>,
) -> Option<Vec<CompletionItem>> {
let symbols: Symbols = query.lock().unwrap().get_symbols_at_pos(position);

Some(
CompletionBuilder::new()
.add(
&symbols
.types
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::TYPE_PARAMETER,
)
.add(
&symbols
.constants
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::CONSTANT,
)
.add(
&symbols
.variables
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::VARIABLE,
)
.add(
&symbols
.functions
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::FUNCTION,
Some(
CompletionBuilder::new()
.add(
&symbols
.types
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::TYPE_PARAMETER,
)
.add(
&symbols
.constants
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::CONSTANT,
)
.add(
&symbols
.variables
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::VARIABLE,
)
.add(
&symbols
.functions
.iter()
.map(|s| s.get_name())
.collect::<Vec<_>>(),
CompletionItemKind::FUNCTION,
)
.build(),
)
}

let name_field = query.lock().unwrap().get_name_field(position, source_code);

match name_field {
Some(fields) => {
return Some(
CompletionBuilder::new()
.add(
&fields.iter().map(|s| s.get_name()).collect::<Vec<_>>(),
CompletionItemKind::FIELD,
)
.build(),
)
.build(),
)
}
None => {
return default(position, query);
}
}
}
23 changes: 0 additions & 23 deletions src/features/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,6 @@ impl HoverContentBuilder {
self
}

pub fn add_list(
mut self,
list_items: Vec<String>,
title: Option<String>,
) -> HoverContentBuilder {
let mut text: String = if let Some(title) = title {
format!("{title}:\n")
} else {
String::new()
};

for item in list_items {
text.push_str("- ");
text.push_str(item.as_str());
text.push('\n');
}
text.push('\n');

self.items.push(MarkedString::String(text));

self
}

pub fn build(self) -> HoverContents {
HoverContents::Array(self.items)
}
Expand Down
2 changes: 0 additions & 2 deletions src/features/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ pub fn rename(
new_name: new_name.clone(),
});

debug!("{:?}", symbol);

Some(WorkspaceEdit::new(build_changes(uri, &symbol, new_name)))
}

Expand Down
10 changes: 0 additions & 10 deletions src/features/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,3 @@ pub fn get_tokens() -> SemanticTokensResult {
data: tokens,
})
}

// fn new_token(node_type: u32, node: Node) -> SemanticToken {
// SemanticToken {
// delta_line: 0,
// delta_start: 0,
// length: 0,
// token_type: 0,
// token_modifiers_bitset: 0,
// }
// }
2 changes: 1 addition & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl File {
}

pub fn get_completion_list(&self, position: Position) -> Option<Vec<CompletionItem>> {
completion::get_list(position, &self.symbol_table_manager)
completion::get_list(position, &self.source_code, &self.symbol_table_manager)
}

pub fn get_hover_info(&self, position: Position) -> Option<HoverContents> {
Expand Down
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ impl LanguageServer for Backend {
.build(),
log_file,
);

if result.is_err() {
self.client
.log_message(MessageType::ERROR, "Log file couldn't be created.")
.await;
}
}


info!("Initializing lsp");

self.plugin_manager.write().unwrap().load_plugins();

let mut completion_temp = CompletionOptions::default();
completion_temp.trigger_characters = Some(vec![".".to_string()]);
Ok(InitializeResult {
capabilities: ServerCapabilities {
semantic_tokens_provider: Some(
Expand All @@ -75,7 +76,7 @@ impl LanguageServer for Backend {
),
),
hover_provider: Some(HoverProviderCapability::Simple(true)),
completion_provider: Some(CompletionOptions::default()),
completion_provider: Some(completion_temp),
text_document_sync: Some(TextDocumentSyncCapability::Options(
TextDocumentSyncOptions {
open_close: Some(true),
Expand Down Expand Up @@ -240,8 +241,6 @@ impl LanguageServer for Backend {
))
};

debug!("rename: {:?}", response);

response
}

Expand Down
Loading

0 comments on commit 87871b5

Please sign in to comment.