MCPcopy Create free account
hub / github.com/GCWing/BitFun / build_command

Method build_command

src/crates/services/services-core/src/lsp/process.rs:880–1071  ·  view source on GitHub ↗

Builds the command based on the runtime type.

(
        runtime_type: &RuntimeType,
        server_bin: &PathBuf,
        config: &ServerConfig,
    )

Source from the content-addressed store, hash-verified

878
879 /// Builds the command based on the runtime type.
880 fn build_command(
881 runtime_type: &RuntimeType,
882 server_bin: &PathBuf,
883 config: &ServerConfig,
884 ) -> Result<tokio::process::Command> {
885 match runtime_type {
886 RuntimeType::Executable => {
887 #[cfg(windows)]
888 {
889 if let Some(ext) = server_bin.extension().and_then(|e| e.to_str()) {
890 let ext_lower = ext.to_lowercase();
891
892 if ext_lower == "bat" || ext_lower == "cmd" {
893 debug!(
894 "Detected batch file (.{}), extracting node command",
895 ext_lower
896 );
897
898 if let Ok(content) = std::fs::read_to_string(server_bin) {
899 let mut script_path: Option<PathBuf> = None;
900
901 for line in content.lines() {
902 let line = line.trim();
903
904 if line.starts_with("node ") || line.starts_with("node.exe ") {
905 info!("Found node execution command: {}", line);
906
907 if let Some(start_quote) = line.find('"') {
908 if let Some(end_quote) =
909 line[start_quote + 1..].find('"')
910 {
911 let path_expr = &line
912 [start_quote + 1..start_quote + 1 + end_quote];
913 debug!("Extracted path expression: {}", path_expr);
914
915 for prev_line in content.lines() {
916 let prev_line = prev_line.trim();
917 if prev_line.starts_with("set ")
918 && prev_line.contains(
919 path_expr
920 .trim_matches('%')
921 .split('%')
922 .next()
923 .unwrap_or(""),
924 )
925 {
926 if let Some(eq_pos) = prev_line.find('=') {
927 let value_part = &prev_line
928 [eq_pos + 1..]
929 .trim_matches('"');
930
931 if let Some(parent) =
932 server_bin.parent()
933 {
934 let mut resolved_path =
935 parent.to_path_buf();
936
937 let rel_part = value_part

Callers

nothing calls this directly

Calls 10

create_tokio_commandFunction · 0.85
trimMethod · 0.80
nextMethod · 0.80
outputMethod · 0.80
replaceMethod · 0.65
create_commandFunction · 0.50
containsMethod · 0.45
popMethod · 0.45
pushMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected