git.delta.rocks / jrsonnet / refs/commits / 04bd9e467c66

difftreelog

refactor remove lsp for now

Yaroslav Bolyukin2024-03-03parent: #627070c.patch.diff
in: master
It was kept to be a consumer of jrsonnet-parser, but wasn't really
working, in future a proper LSP implementation will be developed.

3 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -284,21 +284,6 @@
 ]
 
 [[package]]
-name = "crossbeam-channel"
-version = "0.5.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b"
-dependencies = [
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-utils"
-version = "0.8.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
-
-[[package]]
 name = "crypto-common"
 version = "0.1.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -390,15 +375,6 @@
 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
 
 [[package]]
-name = "form_urlencoded"
-version = "1.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
-dependencies = [
- "percent-encoding",
-]
-
-[[package]]
 name = "generic-array"
 version = "0.14.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -461,16 +437,6 @@
 ]
 
 [[package]]
-name = "idna"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
-dependencies = [
- "unicode-bidi",
- "unicode-normalization",
-]
-
-[[package]]
 name = "indexmap"
 version = "1.9.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -630,19 +596,6 @@
 ]
 
 [[package]]
-name = "jrsonnet-lsp"
-version = "0.5.0-pre96"
-dependencies = [
- "anyhow",
- "jrsonnet-evaluator",
- "jrsonnet-rowan-parser",
- "lsp-server",
- "lsp-types",
- "serde",
- "serde_json",
-]
-
-[[package]]
 name = "jrsonnet-macros"
 version = "0.5.0-pre96"
 dependencies = [
@@ -762,12 +715,6 @@
  "autocfg",
  "scopeguard",
 ]
-
-[[package]]
-name = "log"
-version = "0.4.20"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
 
 [[package]]
 name = "logos"
@@ -812,31 +759,6 @@
 ]
 
 [[package]]
-name = "lsp-server"
-version = "0.7.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "248f65b78f6db5d8e1b1604b4098a28b43d21a8eb1deeca22b1c421b276c7095"
-dependencies = [
- "crossbeam-channel",
- "log",
- "serde",
- "serde_json",
-]
-
-[[package]]
-name = "lsp-types"
-version = "0.95.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "158c1911354ef73e8fe42da6b10c0484cb65c7f1007f28022e847706c1ab6984"
-dependencies = [
- "bitflags 1.3.2",
- "serde",
- "serde_json",
- "serde_repr",
- "url",
-]
-
-[[package]]
 name = "md5"
 version = "0.7.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1023,12 +945,6 @@
 checksum = "36bae92c60fa2398ce4678b98b2c4b5a7c61099961ca1fa305aec04a9ad28922"
 
 [[package]]
-name = "percent-encoding"
-version = "2.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
-
-[[package]]
 name = "ppv-lite86"
 version = "0.2.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1217,17 +1133,6 @@
  "itoa",
  "ryu",
  "serde",
-]
-
-[[package]]
-name = "serde_repr"
-version = "0.1.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.50",
 ]
 
 [[package]]
@@ -1436,24 +1341,9 @@
  "proc-macro2",
  "quote",
  "syn 2.0.50",
-]
-
-[[package]]
-name = "tinyvec"
-version = "1.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
-dependencies = [
- "tinyvec_macros",
 ]
 
 [[package]]
-name = "tinyvec_macros"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
-
-[[package]]
 name = "typenum"
 version = "1.17.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1466,12 +1356,6 @@
 checksum = "a3e5df347f0bf3ec1d670aad6ca5c6a1859cd9ea61d2113125794654ccced68f"
 
 [[package]]
-name = "unicode-bidi"
-version = "0.3.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
-
-[[package]]
 name = "unicode-ident"
 version = "1.0.12"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1482,33 +1366,12 @@
 version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
-
-[[package]]
-name = "unicode-normalization"
-version = "0.1.23"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
-dependencies = [
- "tinyvec",
-]
 
 [[package]]
 name = "unicode-width"
 version = "0.1.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
-
-[[package]]
-name = "url"
-version = "2.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
-dependencies = [
- "form_urlencoded",
- "idna",
- "percent-encoding",
- "serde",
-]
 
 [[package]]
 name = "utf8parse"
deletedcmds/jrsonnet-lsp/Cargo.tomldiffbeforeafterboth
--- a/cmds/jrsonnet-lsp/Cargo.toml
+++ /dev/null
@@ -1,13 +0,0 @@
-[package]
-name = "jrsonnet-lsp"
-version.workspace = true
-edition = "2021"
-
-[dependencies]
-anyhow.workspace = true
-jrsonnet-evaluator.workspace = true
-jrsonnet-rowan-parser.workspace = true
-lsp-server.workspace = true
-lsp-types.workspace = true
-serde.workspace = true
-serde_json.workspace = true
deletedcmds/jrsonnet-lsp/src/main.rsdiffbeforeafterboth
before · cmds/jrsonnet-lsp/src/main.rs
1use std::{fs::File, io::Write, path::PathBuf, str::FromStr};23use lsp_server::{Connection, ErrorCode, Message, Request, RequestId, Response};4use lsp_types::{5	notification::{DidChangeTextDocument, DidOpenTextDocument, Notification},6	request::{DocumentLinkRequest, HoverRequest},7	CompletionOptions, DidChangeTextDocumentParams, DidOpenTextDocumentParams, DocumentLink,8	DocumentLinkOptions, ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind,9	TextDocumentSyncOptions, Url, WorkDoneProgressOptions,10};1112fn main() {13	let mut log = File::create("test").unwrap();14	writeln!(log, "start").unwrap();15	let (connection, io_threads) = Connection::stdio();16	let capabilities = serde_json::to_value(ServerCapabilities {17		completion_provider: Some(CompletionOptions::default()),18		definition_provider: Some(lsp_types::OneOf::Left(true)),19		document_link_provider: Some(DocumentLinkOptions {20			resolve_provider: Some(false),21			work_done_progress_options: WorkDoneProgressOptions::default(),22		}),23		hover_provider: Some(lsp_types::HoverProviderCapability::Simple(true)),24		text_document_sync: Some(TextDocumentSyncCapability::Options(25			TextDocumentSyncOptions {26				change: Some(TextDocumentSyncKind::FULL),27				open_close: Some(true),28				..TextDocumentSyncOptions::default()29			},30		)),31		..ServerCapabilities::default()32	})33	.expect("failed to convert capabilities to json");3435	connection36		.initialize(capabilities)37		.expect("failed to initialize connection");3839	writeln!(log, "initialized").unwrap();4041	main_loop(&mut log, &connection).expect("main loop failed");4243	io_threads.join().expect("failed to join io_threads");44}45fn main_loop(log: &mut File, connection: &Connection) -> anyhow::Result<()> {46	// let mut es = EvaluationState::default();47	// es.set_import_resolver(Box::new(FileImportResolver::default()));4849	let reply = |response: Response| {50		connection51			.sender52			.send(Message::Response(response))53			.expect("failed to respond");54	};5556	for msg in &connection.receiver {57		match msg {58			Message::Response(_) => (),59			Message::Request(req) => {60				if connection.handle_shutdown(&req)? {61					return Ok(());62				}63				if let Some((id, params)) = cast::<DocumentLinkRequest>(&req) {64					reply(Response::new_ok(id, <Vec<DocumentLink>>::new()));65				} else if let Some((id, params)) = cast::<HoverRequest>(&req) {66					let pos = params67						.text_document_position_params68						.text_document69						.uri70						.path();71					let buf = PathBuf::from_str(pos).unwrap();72				// let pos = es73				// 	.map_from_source_location(74				// 		&buf,75				// 		params.text_document_position_params.position.line as usize + 1,76				// 		params.text_document_position_params.position.character as usize + 1,77				// 	)78				// 	.unwrap();79				// let el = ExprLocation(buf.clone().into(), pos as usize, pos as usize);80				// let es2 = es.clone();81				// reply(Response::new_ok(82				// 	id,83				// 	Some(Hover {84				// 		range: None,85				// 		contents: HoverContents::Markup(MarkupContent {86				// 			kind: MarkupKind::Markdown,87				// 			value: es88				// 				.run_in_state_with_breakpoint(el, move || {89				// 					es2.reset_evaluation_state(&buf);90				// 					es2.import_file(&PathBuf::new(), &buf)?91				// 						.to_string()92				// 						.map(|_| ())93				// 				})94				// 				.unwrap()95				// 				.unwrap_or_else(|| Val::Null)96				// 				.value_type()97				// 				.to_string(),98				// 		}),99				// 	}),100				// ));101				} else {102					reply(Response::new_err(103						req.id,104						ErrorCode::MethodNotFound as i32,105						format!("unrecognized request {}", req.method),106					))107				}108				/*109				if let Some((id, params)) = cast::<DocumentLinkRequest>(&req) {110					 let links = handle_links(&files, params).unwrap_or_default();111					 reply(Response::new_ok(id, links));112				} else if let Some((id, params)) = cast::<GotoDefinition>(&req) {113					 if let Some(loc) = handle_goto(&files, params) {114						  reply(Response::new_ok(id, loc))115					 } else {116						  reply(Response::new_ok(id, ()))117					 }118				} else if let Some((id, params)) = cast::<HoverRequest>(&req) {119					 match handle_hover(&files, params) {120						  Some((range, markdown)) => {121								reply(Response::new_ok(122									 id,123									 Hover {124										  contents: HoverContents::Markup(MarkupContent {125												kind: MarkupKind::Markdown,126												value: markdown,127										  }),128										  range,129									 },130								));131						  }132						  None => {133								reply(Response::new_ok(id, ()));134						  }135					 }136				} else if let Some((id, params)) = cast::<Completion>(&req) {137					 let completions = handle_completion(&files, params.text_document_position)138						  .unwrap_or_default();139					 reply(Response::new_ok(id, completions));140				} else141				*/142			}143			Message::Notification(req) => {144				let mut handle = |text: String, uri: Url| {145					writeln!(log, "updated file: {:?}", uri).unwrap();146					let path = match PathBuf::from_str(uri.path()) {147						Ok(x) => x,148						Err(_) => return,149					};150					let (ast, errors) = jrsonnet_rowan_parser::parse(&text);151					// es.add_parsed_file(path.into(), text.into(), parsed)152					// 	.unwrap();153					writeln!(log, "parsed: {:?}", uri).unwrap();154				};155156				match &*req.method {157					DidOpenTextDocument::METHOD => {158						let params: DidOpenTextDocumentParams =159							match serde_json::from_value(req.params) {160								Ok(x) => x,161								Err(_) => continue,162							};163						handle(params.text_document.text, params.text_document.uri);164					}165					DidChangeTextDocument::METHOD => {166						let params: DidChangeTextDocumentParams =167							match serde_json::from_value(req.params) {168								Ok(x) => x,169								Err(_) => continue,170							};171						for change in params.content_changes.into_iter() {172							handle(change.text, params.text_document.uri.clone());173						}174					}175					_ => continue,176				}177			}178		}179	}180	Ok(())181}182fn cast<R>(req: &Request) -> Option<(RequestId, R::Params)>183where184	R: lsp_types::request::Request,185	R::Params: serde::de::DeserializeOwned,186{187	req.clone().extract(R::METHOD).ok()188}