Skip to content

Commit

Permalink
Default to use the lsp home if it exists, otherwise set up directory …
Browse files Browse the repository at this point in the history
…in steel home for it (#257)

* default to use the lsp home if it exists

* create the directory if it doesn't exist
  • Loading branch information
mattwparas authored Aug 14, 2024
1 parent d31238b commit 2c0a755
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
1 change: 0 additions & 1 deletion crates/steel-core/src/compiler/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ create_prelude!(
"#%private/steel/match",
for_syntax "#%private/steel/control",
for_syntax "#%private/steel/contract"
// for_syntax "#%private/steel/match"
);

#[cfg(not(target_arch = "wasm32"))]
Expand Down
30 changes: 23 additions & 7 deletions crates/steel-language-server/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ use ropey::Rope;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use steel::{
compiler::passes::analysis::{
query_top_level_define, query_top_level_define_on_condition, RequiredIdentifierInformation,
SemanticAnalysis,
compiler::{
modules::steel_home,
passes::analysis::{
query_top_level_define, query_top_level_define_on_condition,
RequiredIdentifierInformation, SemanticAnalysis,
},
},
parser::{
ast::ExprKind, expander::SteelMacro, interner::InternedString, parser::SourceId,
Expand All @@ -36,6 +39,22 @@ use crate::diagnostics::{
DiagnosticContext, DiagnosticGenerator, FreeIdentifiersAndUnusedIdentifiers, StaticArityChecker,
};

pub fn lsp_home() -> PathBuf {
if let Ok(home) = std::env::var("STEEL_LSP_HOME") {
return PathBuf::from(home);
}

let mut home_directory =
PathBuf::from(steel_home().expect("Unable to find steel home location"));
home_directory.push("lsp");

if !home_directory.exists() {
std::fs::create_dir_all(&home_directory).expect("Unable to create the lsp home directory");
}

home_directory
}

pub const LEGEND_TYPE: &[SemanticTokenType] = &[
SemanticTokenType::FUNCTION,
SemanticTokenType::VARIABLE,
Expand Down Expand Up @@ -941,10 +960,7 @@ fn configure_lints() -> std::result::Result<UserDefinedLintEngine, Box<dyn Error
engine_lints.write().unwrap().insert(name);
});

let mut directory = PathBuf::from(
std::env::var("STEEL_LSP_HOME").expect("Have you set your STEEL_LSP_HOME path?"),
);

let mut directory = lsp_home();
directory.push("lints");

engine.register_module(diagnostics);
Expand Down
5 changes: 2 additions & 3 deletions crates/steel-language-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use steel::{
parser::interner::InternedString,
steel_vm::{engine::Engine, register_fn::RegisterFn},
};
use steel_language_server::backend::{Backend, ExternalModuleResolver, ENGINE};
use steel_language_server::backend::{lsp_home, Backend, ExternalModuleResolver, ENGINE};

use tower_lsp::{LspService, Server};

Expand Down Expand Up @@ -42,8 +42,7 @@ async fn main() {
cloned_additional_search_paths.insert(path);
});

let home_directory =
std::env::var("STEEL_LSP_HOME").expect("Have you set your STEEL_LSP_HOME path?");
let home_directory = lsp_home();

ENGINE.with(|x| {
x.borrow_mut().register_module_resolver(
Expand Down
8 changes: 3 additions & 5 deletions libs/steel-sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ impl SqlitePreparedStatement {

while let Some(row) = rows.next()? {
if let Some(width) = width {
// TODO: Save the row length for the next iteration, so that we can pre allocate
// the row width
let mut computed_row: RVec<FFIValue> = RVec::with_capacity(width);

for i in 0..width {
Expand All @@ -189,9 +187,6 @@ impl SqlitePreparedStatement {

results.push(FFIValue::Vector(computed_row));
} else {
// TODO: Save the row length for the next iteration, so that we can pre allocate
// the row width
// let mut computed_row: Vec<SteelVal> = Vec::new();
let mut i = 0;
let mut computed_row: RVec<FFIValue> = RVec::new();

Expand Down Expand Up @@ -252,6 +247,9 @@ impl<'a> ToSql for FFIWrapper<'a> {
FFIArg::IntV(i) => Ok(ToSqlOutput::Owned(Value::Integer(*i as i64))),
FFIArg::Void => Ok(ToSqlOutput::Owned(Value::Null)),
FFIArg::StringV(s) => Ok(ToSqlOutput::Owned(Value::Text(s.to_string()))),
FFIArg::StringRef(s) => Ok(ToSqlOutput::Borrowed(rusqlite::types::ValueRef::Text(
s.as_bytes(),
))),
// FFIValue::Vector(_) => todo!(),
// FFIValue::CharV { c } => todo!(),
// FFIValue::Custom { custom } => todo!(),
Expand Down

0 comments on commit 2c0a755

Please sign in to comment.