Skip to content

Commit

Permalink
Merge pull request #458 from erg-lang/molc
Browse files Browse the repository at this point in the history
Add `molc`
  • Loading branch information
mtshiba authored Sep 7, 2023
2 parents 6ca5e07 + b14a00c commit e1280e7
Show file tree
Hide file tree
Showing 25 changed files with 251 additions and 797 deletions.
127 changes: 16 additions & 111 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions crates/els/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ experimental = ["erg_common/experimental", "erg_compiler/experimental"]
[dependencies]
erg_common = { workspace = true, features = ["els"] }
erg_compiler = { workspace = true, features = ["els"] }
molc = { version = "0.1.0" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.85"
lsp-types = { version = "0.93.2", features = ["proposed"] }

[dev-dependencies]
gag = "1"

[lib]
path = "lib.rs"

Expand Down
8 changes: 4 additions & 4 deletions crates/els/call_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use lsp_types::{
};

use crate::_log;
use crate::server::{ELSResult, Server};
use crate::server::{ELSResult, RedirectableStdout, Server};
use crate::symbol::symbol_kind;
use crate::util::{abs_loc_to_lsp_loc, loc_to_pos, NormalizedUrl};

Expand All @@ -35,7 +35,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
params: CallHierarchyIncomingCallsParams,
) -> ELSResult<Option<Vec<CallHierarchyIncomingCall>>> {
let mut res = vec![];
_log!("call hierarchy incoming calls requested: {params:?}");
_log!(self, "call hierarchy incoming calls requested: {params:?}");
let Some(data) = params.item.data.as_ref().and_then(|d| d.as_str()) else {
return Ok(None);
};
Expand Down Expand Up @@ -80,15 +80,15 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
&mut self,
params: CallHierarchyOutgoingCallsParams,
) -> ELSResult<Option<Vec<CallHierarchyOutgoingCall>>> {
_log!("call hierarchy outgoing calls requested: {params:?}");
_log!(self, "call hierarchy outgoing calls requested: {params:?}");
Ok(None)
}

pub(crate) fn handle_call_hierarchy_prepare(
&mut self,
params: CallHierarchyPrepareParams,
) -> ELSResult<Option<Vec<CallHierarchyItem>>> {
_log!("call hierarchy prepare requested: {params:?}");
_log!(self, "call hierarchy prepare requested: {params:?}");
let mut res = vec![];
let uri = NormalizedUrl::new(params.text_document_position_params.text_document.uri);
let pos = params.text_document_position_params.position;
Expand Down
16 changes: 8 additions & 8 deletions crates/els/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use lsp_types::{
Position, Range, TextEdit, Url, WorkspaceEdit,
};

use crate::server::{send_log, ELSResult, Server};
use crate::server::{ELSResult, RedirectableStdout, Server};
use crate::util::{self, NormalizedUrl};

impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
Expand All @@ -29,11 +29,11 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
};
let mut map = HashMap::new();
let Some(visitor) = self.get_visitor(&uri) else {
send_log("visitor not found")?;
self.send_log("visitor not found")?;
return Ok(None);
};
let Some(result) = self.analysis_result.get(&uri) else {
send_log("artifact not found")?;
self.send_log("artifact not found")?;
return Ok(None);
};
let warns = result
Expand All @@ -50,7 +50,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
match visitor.get_min_expr(pos) {
Some(Expr::Def(def)) => {
let Some(mut range) = util::loc_to_range(def.loc()) else {
send_log("range not found")?;
self.send_log("range not found")?;
continue;
};
let next = lsp_types::Range {
Expand All @@ -72,7 +72,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
}
Some(";") => range.end.character += 1,
Some(other) => {
send_log(format!("? {other}"))?;
self.send_log(format!("? {other}"))?;
}
}
let edit = TextEdit::new(range, "".to_string());
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
&mut self,
params: CodeActionParams,
) -> ELSResult<Option<CodeActionResponse>> {
send_log(format!("code action requested: {params:?}"))?;
self.send_log(format!("code action requested: {params:?}"))?;
let result = match params
.context
.only
Expand All @@ -238,7 +238,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
Some("quickfix") => self.send_quick_fix(&params)?,
None => self.send_normal_action(&params)?,
Some(other) => {
send_log(&format!("Unknown code action requested: {other}"))?;
self.send_log(&format!("Unknown code action requested: {other}"))?;
vec![]
}
};
Expand All @@ -254,7 +254,7 @@ impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
&mut self,
action: CodeAction,
) -> ELSResult<CodeAction> {
send_log(format!("code action resolve requested: {action:?}"))?;
self.send_log(format!("code action resolve requested: {action:?}"))?;
match &action.title[..] {
"Extract into function" | "Extract into variable" => {
self.resolve_extract_action(action)
Expand Down
4 changes: 2 additions & 2 deletions crates/els/code_lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use erg_compiler::hir::Expr;

use lsp_types::{CodeLens, CodeLensParams};

use crate::server::{send_log, ELSResult, Server};
use crate::server::{ELSResult, RedirectableStdout, Server};
use crate::util::{self, NormalizedUrl};

impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
pub(crate) fn handle_code_lens(
&mut self,
params: CodeLensParams,
) -> ELSResult<Option<Vec<CodeLens>>> {
send_log("code lens requested")?;
self.send_log("code lens requested")?;
let uri = NormalizedUrl::new(params.text_document.uri);
// TODO: parallelize
let result = [
Expand Down
6 changes: 3 additions & 3 deletions crates/els/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use erg_compiler::hir::Expr;
use lsp_types::{Command, ExecuteCommandParams, Location, Url};

use crate::_log;
use crate::server::{ELSResult, Server};
use crate::server::{ELSResult, RedirectableStdout, Server};
use crate::util::{self, NormalizedUrl};

impl<Checker: BuildRunnable, Parser: Parsable> Server<Checker, Parser> {
pub(crate) fn handle_execute_command(
&mut self,
params: ExecuteCommandParams,
) -> ELSResult<Option<Value>> {
_log!("command requested: {}", params.command);
_log!(self, "command requested: {}", params.command);
#[allow(clippy::match_single_binding)]
match &params.command[..] {
other => {
_log!("unknown command {other}: {params:?}");
_log!(self, "unknown command {other}: {params:?}");
Ok(None)
}
}
Expand Down
Loading

0 comments on commit e1280e7

Please sign in to comment.