Compare commits

...

4 Commits

Author SHA1 Message Date
879d7ec4f4 Cut release v0.19.2 (#2247) 2024-04-25 14:38:25 -04:00
f6838b9b14 always ensure the dirs exist (#2245)
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-25 17:07:24 +00:00
cb75c47631 fix env vars for lsp server to match other .env vars (#2243)
fix env vars for lsp

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-25 16:41:39 +00:00
9b95ec1083 fix relevant extensions (#2241)
* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
2024-04-25 08:36:45 -07:00
12 changed files with 98 additions and 36 deletions

View File

@ -1,6 +1,6 @@
{
"name": "untitled-app",
"version": "0.19.1",
"version": "0.19.2",
"private": true,
"dependencies": {
"@codemirror/autocomplete": "^6.16.0",

23
src-tauri/Cargo.lock generated
View File

@ -751,6 +751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
@ -763,6 +764,20 @@ dependencies = [
"anstyle",
"clap_lex",
"strsim 0.11.1",
"unicase",
"unicode-width",
]
[[package]]
name = "clap_derive"
version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
dependencies = [
"heck 0.5.0",
"proc-macro2",
"quote",
"syn 2.0.60",
]
[[package]]
@ -2412,6 +2427,7 @@ dependencies = [
"base64 0.22.0",
"bson",
"chrono",
"clap",
"dashmap",
"databake",
"derive-docs",
@ -2471,6 +2487,7 @@ dependencies = [
"bigdecimal",
"bytes",
"chrono",
"clap",
"data-encoding",
"format_serde_error",
"futures",
@ -5886,6 +5903,12 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
[[package]]
name = "unicode-width"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "untrusted"
version = "0.9.0"

View File

@ -52,14 +52,22 @@ async fn set_state(app: tauri::AppHandle, state: Option<ProjectState>) -> Result
Ok(())
}
fn get_app_settings_file_path(app: &tauri::AppHandle) -> Result<PathBuf, InvokeError> {
async fn get_app_settings_file_path(app: &tauri::AppHandle) -> Result<PathBuf, InvokeError> {
let app_config_dir = app.path().app_config_dir()?;
// Ensure this directory exists.
if !app_config_dir.exists() {
tokio::fs::create_dir_all(&app_config_dir)
.await
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
}
Ok(app_config_dir.join(SETTINGS_FILE_NAME))
}
#[tauri::command]
async fn read_app_settings_file(app: tauri::AppHandle) -> Result<Configuration, InvokeError> {
let mut settings_path = get_app_settings_file_path(&app)?;
let mut settings_path = get_app_settings_file_path(&app).await?;
let mut needs_migration = false;
// Check if this file exists.
@ -104,7 +112,7 @@ async fn read_app_settings_file(app: tauri::AppHandle) -> Result<Configuration,
#[tauri::command]
async fn write_app_settings_file(app: tauri::AppHandle, configuration: Configuration) -> Result<(), InvokeError> {
let settings_path = get_app_settings_file_path(&app)?;
let settings_path = get_app_settings_file_path(&app).await?;
let contents = toml::to_string_pretty(&configuration).map_err(|e| InvokeError::from_anyhow(e.into()))?;
tokio::fs::write(settings_path, contents.as_bytes())
.await
@ -113,13 +121,19 @@ async fn write_app_settings_file(app: tauri::AppHandle, configuration: Configura
Ok(())
}
fn get_project_settings_file_path(app_settings: Configuration, project_name: &str) -> Result<PathBuf, InvokeError> {
Ok(app_settings
.settings
.project
.directory
.join(project_name)
.join(PROJECT_SETTINGS_FILE_NAME))
async fn get_project_settings_file_path(
app_settings: Configuration,
project_name: &str,
) -> Result<PathBuf, InvokeError> {
let project_dir = app_settings.settings.project.directory.join(project_name);
if !project_dir.exists() {
tokio::fs::create_dir_all(&project_dir)
.await
.map_err(|e| InvokeError::from_anyhow(e.into()))?;
}
Ok(project_dir.join(PROJECT_SETTINGS_FILE_NAME))
}
#[tauri::command]
@ -127,7 +141,7 @@ async fn read_project_settings_file(
app_settings: Configuration,
project_name: &str,
) -> Result<ProjectConfiguration, InvokeError> {
let settings_path = get_project_settings_file_path(app_settings, project_name)?;
let settings_path = get_project_settings_file_path(app_settings, project_name).await?;
// Check if this file exists.
if !settings_path.exists() {
@ -149,7 +163,7 @@ async fn write_project_settings_file(
project_name: &str,
configuration: ProjectConfiguration,
) -> Result<(), InvokeError> {
let settings_path = get_project_settings_file_path(app_settings, project_name)?;
let settings_path = get_project_settings_file_path(app_settings, project_name).await?;
let contents = toml::to_string_pretty(&configuration).map_err(|e| InvokeError::from_anyhow(e.into()))?;
tokio::fs::write(settings_path, contents.as_bytes())
.await

View File

@ -71,5 +71,5 @@
}
},
"productName": "Zoo Modeling App",
"version": "0.19.1"
"version": "0.19.2"
}

View File

@ -3,7 +3,7 @@ import type * as LSP from 'vscode-languageserver-protocol'
import React, { createContext, useMemo, useEffect, useContext } from 'react'
import { FromServer, IntoServer } from 'editor/plugins/lsp/codec'
import Client from '../editor/plugins/lsp/client'
import { DEV, TEST } from 'env'
import { TEST, VITE_KC_API_BASE_URL } from 'env'
import kclLanguage from 'editor/plugins/lsp/kcl/language'
import { copilotPlugin } from 'editor/plugins/lsp/copilot'
import { useStore } from 'useStore'
@ -103,7 +103,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
wasmUrl: wasmUrl(),
token: token,
baseUnit: defaultUnit.current,
devMode: DEV,
apiBaseUrl: VITE_KC_API_BASE_URL,
}
lspWorker.postMessage({
worker: LspWorker.Kcl,
@ -177,7 +177,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
const initEvent: CopilotWorkerOptions = {
wasmUrl: wasmUrl(),
token: token,
devMode: DEV,
apiBaseUrl: VITE_KC_API_BASE_URL,
}
lspWorker.postMessage({
worker: LspWorker.Copilot,

View File

@ -8,13 +8,13 @@ export interface KclWorkerOptions {
wasmUrl: string
token: string
baseUnit: UnitLength
devMode: boolean
apiBaseUrl: string
}
export interface CopilotWorkerOptions {
wasmUrl: string
token: string
devMode: boolean
apiBaseUrl: string
}
export enum LspWorkerEventType {

View File

@ -28,11 +28,11 @@ const initialise = async (wasmUrl: string) => {
export async function copilotLspRun(
config: ServerConfig,
token: string,
devMode: boolean = false
baseUrl: string
) {
try {
console.log('starting copilot lsp')
await copilot_lsp_run(config, token, devMode)
await copilot_lsp_run(config, token, baseUrl)
} catch (e: any) {
console.log('copilot lsp failed', e)
// We can't restart here because a moved value, we should do this another way.
@ -44,11 +44,11 @@ export async function kclLspRun(
engineCommandManager: EngineCommandManager | null,
token: string,
baseUnit: string,
devMode: boolean = false
baseUrl: string
) {
try {
console.log('start kcl lsp')
await kcl_lsp_run(config, engineCommandManager, baseUnit, token, devMode)
await kcl_lsp_run(config, engineCommandManager, baseUnit, token, baseUrl)
} catch (e: any) {
console.log('kcl lsp failed', e)
// We can't restart here because a moved value, we should do this another way.
@ -80,12 +80,12 @@ onmessage = function (event) {
null,
kclData.token,
kclData.baseUnit,
kclData.devMode
kclData.apiBaseUrl
)
break
case LspWorker.Copilot:
let copilotData = eventData as CopilotWorkerOptions
copilotLspRun(config, copilotData.token, copilotData.devMode)
copilotLspRun(config, copilotData.token, copilotData.apiBaseUrl)
break
}
})

View File

@ -1974,6 +1974,7 @@ dependencies = [
"bigdecimal",
"bytes",
"chrono",
"clap",
"data-encoding",
"format_serde_error",
"futures",
@ -4726,6 +4727,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"bson",
"clap",
"console_error_panic_hook",
"futures",
"gloo-utils",

View File

@ -11,6 +11,7 @@ crate-type = ["cdylib"]
[dependencies]
bson = { version = "2.10.0", features = ["uuid-1", "chrono"] }
clap = "4.5.4"
gloo-utils = "0.2.0"
kcl-lib = { path = "kcl" }
kittycad = { workspace = true }

View File

@ -16,7 +16,7 @@ async-recursion = "1.1.0"
async-trait = "0.1.80"
base64 = "0.22.0"
chrono = "0.4.38"
clap = { version = "4.5.4", features = ["cargo", "derive", "env", "unicode"], optional = true }
clap = { version = "4.5.4", default-features = false, optional = true }
dashmap = "5.5.3"
databake = { version = "0.1.7", features = ["derive"] }
derive-docs = { version = "0.1.17", path = "../derive-docs" }
@ -24,7 +24,7 @@ form_urlencoded = "1.2.1"
futures = { version = "0.3.30" }
git_rev = "0.1.0"
gltf-json = "1.4.0"
kittycad = { workspace = true }
kittycad = { workspace = true, features = ["clap"] }
kittycad-execution-plan-macros = { workspace = true }
kittycad-execution-plan-traits = { workspace = true }
lazy_static = "1.4.0"
@ -61,7 +61,7 @@ tokio-tungstenite = { version = "0.21.0", features = ["rustls-tls-native-roots"]
tower-lsp = { version = "0.20.0", features = ["proposed"] }
[features]
default = ["engine"]
default = ["cli", "engine"]
cli = ["dep:clap"]
engine = []

View File

@ -3,9 +3,23 @@
use std::path::Path;
use anyhow::Result;
use clap::ValueEnum;
use crate::settings::types::file::FileEntry;
lazy_static::lazy_static! {
static ref RELEVANT_EXTENSIONS: Vec<String> = {
let mut relevant_extensions = vec!["kcl".to_string(), "stp".to_string(), "glb".to_string()];
let named_extensions = kittycad::types::FileImportFormat::value_variants()
.iter()
.map(|x| format!("{}", x))
.collect::<Vec<String>>();
// Add all the default import formats.
relevant_extensions.extend_from_slice(&named_extensions);
relevant_extensions
};
}
/// Walk a directory recursively and return a list of all files.
#[async_recursion::async_recursion]
pub async fn walk_dir<P: AsRef<Path> + Send>(dir: P) -> Result<FileEntry> {
@ -27,6 +41,9 @@ pub async fn walk_dir<P: AsRef<Path> + Send>(dir: P) -> Result<FileEntry> {
if e.file_type().await?.is_dir() {
children.push(walk_dir(&e.path()).await?);
} else {
if !is_relevant_file(&e.path())? {
continue;
}
children.push(FileEntry {
name: e.file_name().to_string_lossy().to_string(),
path: e.path().display().to_string(),
@ -40,3 +57,12 @@ pub async fn walk_dir<P: AsRef<Path> + Send>(dir: P) -> Result<FileEntry> {
Ok(entry)
}
/// Check if a file is relevant for the application.
fn is_relevant_file<P: AsRef<Path>>(path: P) -> Result<bool> {
if let Some(ext) = path.as_ref().extension() {
Ok(RELEVANT_EXTENSIONS.contains(&ext.to_string_lossy().to_string()))
} else {
Ok(false)
}
}

View File

@ -198,7 +198,7 @@ pub async fn kcl_lsp_run(
engine_manager: Option<kcl_lib::engine::conn_wasm::EngineCommandManager>,
units: &str,
token: String,
is_dev: bool,
baseurl: String,
) -> Result<(), JsValue> {
console_error_panic_hook::set_once();
@ -216,9 +216,7 @@ pub async fn kcl_lsp_run(
let token_types = kcl_lib::token::TokenType::all_semantic_token_types().unwrap();
let mut zoo_client = kittycad::Client::new(token);
if is_dev {
zoo_client.set_base_url("https://api.dev.zoo.dev");
}
zoo_client.set_base_url(baseurl.as_str());
let file_manager = Arc::new(kcl_lib::fs::FileManager::new(fs));
@ -313,7 +311,7 @@ pub async fn kcl_lsp_run(
// NOTE: input needs to be an AsyncIterator<Uint8Array, never, void> specifically
#[wasm_bindgen]
pub async fn copilot_lsp_run(config: ServerConfig, token: String, is_dev: bool) -> Result<(), JsValue> {
pub async fn copilot_lsp_run(config: ServerConfig, token: String, baseurl: String) -> Result<(), JsValue> {
console_error_panic_hook::set_once();
let ServerConfig {
@ -323,9 +321,7 @@ pub async fn copilot_lsp_run(config: ServerConfig, token: String, is_dev: bool)
} = config;
let mut zoo_client = kittycad::Client::new(token);
if is_dev {
zoo_client.set_base_url("https://api.dev.zoo.dev");
}
zoo_client.set_base_url(baseurl.as_str());
let file_manager = Arc::new(kcl_lib::fs::FileManager::new(fs));