Skip to content

Commit 86100aa

Browse files
committed
chore: reorganizing lsp commands
1 parent e001b4a commit 86100aa

File tree

9 files changed

+157
-193
lines changed

9 files changed

+157
-193
lines changed

client/package-lock.json

Lines changed: 52 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@rollup/plugin-json": "^4.1.0",
99
"adm-zip": "^0.5.9",
1010
"encoding": "^0.1.13",
11-
"node-fetch": "^3.2.3",
11+
"node-fetch": "^2.6.7",
1212
"vscode-languageclient": "^7.0.0"
1313
},
1414
"devDependencies": {

client/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mkdirSync, promises as fs } from 'fs'
22
import * as vscode from 'vscode'
3-
import * as lsp from 'vscode-languageclient'
3+
import * as lsp from 'vscode-languageclient/node'
44
import * as commands from './commands'
55
import { log } from './log'
66
import { LanguageClient } from './lspClient'
@@ -54,7 +54,7 @@ export class Extension {
5454
const lspBinary = process.env['MCSHADER_DEBUG'] ?
5555
this.context.asAbsolutePath(path.join('server', 'target', 'debug', 'mcshader-lsp')) +
5656
(process.platform === 'win32' ? '.exe' : '') :
57-
path.join(this.context.globalStoragePath, 'mcshader-lsp')
57+
path.join(this.context.globalStorageUri.fsPath, 'mcshader-lsp')
5858

5959
const filewatcherGlob = this.fileAssociationsToGlob(this.getGLSLFileAssociations())
6060

server/src/commands/graph_dot.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use std::cell::RefCell;
2+
use std::fs::OpenOptions;
3+
use std::io::prelude::*;
4+
use std::path::Path;
5+
use std::rc::Rc;
6+
7+
use petgraph::dot::Config;
8+
use serde_json::Value;
9+
10+
use petgraph::dot;
11+
12+
use anyhow::{format_err, Result};
13+
use slog_scope::info;
14+
15+
use crate::graph::CachedStableGraph;
16+
17+
use super::Invokeable;
18+
19+
pub struct GraphDotCommand {
20+
pub graph: Rc<RefCell<CachedStableGraph>>,
21+
}
22+
23+
impl Invokeable for GraphDotCommand {
24+
fn run_command(&self, root: &Path, _: &[Value]) -> Result<Value> {
25+
let filepath = root.join("graph.dot");
26+
27+
info!("generating dot file"; "path" => filepath.as_os_str().to_str());
28+
29+
let mut file = OpenOptions::new().truncate(true).write(true).create(true).open(filepath).unwrap();
30+
31+
let mut write_data_closure = || -> Result<(), std::io::Error> {
32+
let graph = self.graph.as_ref();
33+
34+
file.seek(std::io::SeekFrom::Start(0))?;
35+
file.write_all("digraph {\n\tgraph [splines=ortho]\n\tnode [shape=box]\n".as_bytes())?;
36+
file.write_all(
37+
dot::Dot::with_config(&graph.borrow().graph, &[Config::GraphContentOnly])
38+
.to_string()
39+
.as_bytes(),
40+
)?;
41+
file.write_all("\n}".as_bytes())?;
42+
file.flush()?;
43+
file.seek(std::io::SeekFrom::Start(0))?;
44+
Ok(())
45+
};
46+
47+
match write_data_closure() {
48+
Err(err) => Err(format_err!("error generating graphviz data: {}", err)),
49+
_ => Ok(Value::Null),
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)