-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from whistle-lang/lunatic
feat: Compile tips + fix types
- Loading branch information
Showing
26 changed files
with
3,142 additions
and
715 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
[package] | ||
name = "whistle_cli" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
authors = ["the Whistle authors"] | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "whistle" | ||
path = "src/main.rs" | ||
|
||
|
||
[dependencies] | ||
whistle_ast = { path = "../ast/" } | ||
whistle_common = { path = "../common/" } | ||
whistle_compiler = { path = "../compiler/" } | ||
whistle_lexer = { path = "../lexer/" } | ||
whistle_parser = { path = "../parser/" } | ||
whistle_lexer = { path = "../lexer" } | ||
whistle_parser = { path = "../parser" } | ||
whistle_common = { path = "../common" } | ||
whistle_ast = { path = "../ast" } | ||
whistle_compiler = { path = "../compiler" } | ||
whistle_preprocessor = { path = "../preprocessor" } | ||
clap = "2.33.3" | ||
clap = { version = "4.0.29", features = ["derive"] } | ||
wasmprinter = "0.2.45" | ||
wasmtime = "12.0.2" | ||
wasmtime-wasi = "12.0.2" | ||
tokio = { version = "1.23.0", features = ["full"] } | ||
tokio-util = { version = "0.7", features = ["compat"] } | ||
tower-lsp = { version = "0.20.0"} | ||
toml = "0.7.2" | ||
tracing-subscriber = "0.3" | ||
serde = { version = "1.0.149", features = ["derive"] } | ||
serde_json = "1.0.89" | ||
futures = "0.3.25" | ||
ropey = "1.6.0" | ||
uuid = { version = "1.2.2", features = ["v4", "fast-rng", "macro-diagnostics"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod lsp; | ||
|
||
pub use lsp::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
use ropey::Rope; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
use tokio::sync::RwLock; | ||
use tower_lsp::jsonrpc::Result; | ||
use tower_lsp::lsp_types::*; | ||
use tower_lsp::{Client, LanguageServer}; | ||
|
||
#[derive(Debug)] | ||
pub struct Document { | ||
pub language_id: String, | ||
pub text: Rope, | ||
} | ||
|
||
impl Document { | ||
pub fn new(language_id: String, text: Rope) -> Self { | ||
Self { language_id, text } | ||
} | ||
} | ||
#[derive(Debug)] | ||
pub struct WhistleBackend { | ||
pub client: Client, | ||
pub document_map: Arc<RwLock<HashMap<String, Document>>>, | ||
} | ||
|
||
#[tower_lsp::async_trait] | ||
impl LanguageServer for WhistleBackend { | ||
async fn initialize(&self, _: InitializeParams) -> Result<InitializeResult> { | ||
Ok(InitializeResult { | ||
capabilities: ServerCapabilities { | ||
text_document_sync: Some(TextDocumentSyncCapability::Kind( | ||
TextDocumentSyncKind::FULL, | ||
)), | ||
hover_provider: Some(HoverProviderCapability::Simple(true)), | ||
completion_provider: Some(CompletionOptions::default()), | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}) | ||
} | ||
|
||
async fn initialized(&self, _: InitializedParams) { | ||
self.client | ||
.log_message(MessageType::INFO, "Whistle language server initialized!") | ||
.await; | ||
} | ||
|
||
async fn shutdown(&self) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
// async fn did_change_workspace_folders(&self, _: DidChangeWorkspaceFoldersParams) { | ||
// self.client | ||
// .log_message(MessageType::INFO, "workspace folders changed!") | ||
// .await; | ||
// } | ||
|
||
// async fn did_change_configuration(&self, _: DidChangeConfigurationParams) { | ||
// self.client | ||
// .log_message(MessageType::INFO, "configuration changed!") | ||
// .await; | ||
// } | ||
|
||
// async fn did_change_watched_files(&self, _: DidChangeWatchedFilesParams) { | ||
// self.client | ||
// .log_message(MessageType::INFO, "watched files have changed!") | ||
// .await; | ||
// } | ||
async fn did_open(&self, params: DidOpenTextDocumentParams) { | ||
let rope = ropey::Rope::from_str(¶ms.text_document.text); | ||
let uri = params.text_document.uri.to_string(); | ||
*self | ||
.document_map | ||
.write() | ||
.await | ||
.entry(uri.clone()) | ||
.or_insert(Document::new("unknown".to_owned(), Rope::new())) = | ||
Document::new(params.text_document.language_id, rope); | ||
} | ||
|
||
async fn did_change(&self, params: DidChangeTextDocumentParams) { | ||
let rope = ropey::Rope::from_str(¶ms.content_changes[0].text); | ||
let uri = params.text_document.uri.to_string(); | ||
let mut document_map = self.document_map.write().await; | ||
let doc = document_map | ||
.entry(uri.clone()) | ||
.or_insert(Document::new("unknown".to_owned(), Rope::new())); | ||
doc.text = rope; | ||
self.client | ||
.log_message(MessageType::INFO, format!("{}", doc.text.to_string())) | ||
.await; | ||
} | ||
|
||
// async fn did_save(&self, _: DidSaveTextDocumentParams) { | ||
// self.client | ||
// .log_message(MessageType::INFO, "file saved!") | ||
// .await; | ||
// } | ||
|
||
// async fn did_close(&self, _: DidCloseTextDocumentParams) { | ||
// self.client | ||
// .log_message(MessageType::INFO, "file closed!") | ||
// .await; | ||
// } | ||
async fn completion(&self, _: CompletionParams) -> Result<Option<CompletionResponse>> { | ||
Ok(Some(CompletionResponse::Array(vec![ | ||
//types | ||
CompletionItem::new_simple("i32".to_string(), "32-bit signed integer type".to_string()), | ||
CompletionItem::new_simple("i64".to_string(), "64-bit signed integer type".to_string()), | ||
CompletionItem::new_simple( | ||
"u32".to_string(), | ||
"32-bit unsigned integer type".to_string(), | ||
), | ||
CompletionItem::new_simple( | ||
"u64".to_string(), | ||
"64-bit unsigned integer type".to_string(), | ||
), | ||
CompletionItem::new_simple("f32".to_string(), "32-bit floating point type".to_string()), | ||
CompletionItem::new_simple("f64".to_string(), "64-bit floating point type".to_string()), | ||
CompletionItem::new_simple("str".to_string(), "string".to_string()), | ||
CompletionItem::new_simple("char".to_string(), "single character".to_string()), | ||
CompletionItem::new_simple("bool".to_string(), "boolean".to_string()), | ||
CompletionItem::new_simple("none".to_string(), "no value".to_string()), | ||
CompletionItem::new_simple("number".to_string(), "number type".to_string()), | ||
CompletionItem::new_simple("int".to_string(), "int type".to_string()), | ||
//keywords | ||
CompletionItem::new_simple("import".to_string(), "import declaration".to_string()), | ||
CompletionItem::new_simple("builtin".to_string(), "builtin declaration".to_string()), | ||
CompletionItem::new_simple("fn".to_string(), "declares a function".to_string()), | ||
CompletionItem::new_simple("export".to_string(), "export declaration".to_string()), | ||
CompletionItem::new_simple("return".to_string(), "return statement".to_string()), | ||
CompletionItem::new_simple("if".to_string(), "if statement".to_string()), | ||
CompletionItem::new_simple("else".to_string(), "else statement".to_string()), | ||
CompletionItem::new_simple("while".to_string(), "while statement".to_string()), | ||
CompletionItem::new_simple("break".to_string(), "break statement".to_string()), | ||
CompletionItem::new_simple("continue".to_string(), "continue statement".to_string()), | ||
CompletionItem::new_simple( | ||
"var".to_string(), | ||
"declares a function-scoped or globally-scoped variable".to_string(), | ||
), | ||
CompletionItem::new_simple( | ||
"val".to_string(), | ||
"declares a constant variable".to_string(), | ||
), | ||
]))) | ||
} | ||
|
||
async fn hover(&self, _: HoverParams) -> Result<Option<Hover>> { | ||
// let _markdown = MarkupContent { | ||
// kind: MarkupKind::Markdown, | ||
// value: [ | ||
// "# Header", | ||
// "Some text", | ||
// ] | ||
// .join("\n"), | ||
// }; | ||
Ok(Some(Hover { | ||
contents: HoverContents::Scalar(MarkedString::String("".to_string())), | ||
/// HoverContents::Markup(markdown), | ||
range: None, | ||
})) | ||
} | ||
} |
Oops, something went wrong.