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", "name": "untitled-app",
"version": "0.19.1", "version": "0.19.2",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@codemirror/autocomplete": "^6.16.0", "@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" checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
"clap_derive",
] ]
[[package]] [[package]]
@ -763,6 +764,20 @@ dependencies = [
"anstyle", "anstyle",
"clap_lex", "clap_lex",
"strsim 0.11.1", "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]] [[package]]
@ -2412,6 +2427,7 @@ dependencies = [
"base64 0.22.0", "base64 0.22.0",
"bson", "bson",
"chrono", "chrono",
"clap",
"dashmap", "dashmap",
"databake", "databake",
"derive-docs", "derive-docs",
@ -2471,6 +2487,7 @@ dependencies = [
"bigdecimal", "bigdecimal",
"bytes", "bytes",
"chrono", "chrono",
"clap",
"data-encoding", "data-encoding",
"format_serde_error", "format_serde_error",
"futures", "futures",
@ -5886,6 +5903,12 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
[[package]]
name = "unicode-width"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]] [[package]]
name = "untrusted" name = "untrusted"
version = "0.9.0" version = "0.9.0"

View File

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

View File

@ -71,5 +71,5 @@
} }
}, },
"productName": "Zoo Modeling App", "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 React, { createContext, useMemo, useEffect, useContext } from 'react'
import { FromServer, IntoServer } from 'editor/plugins/lsp/codec' import { FromServer, IntoServer } from 'editor/plugins/lsp/codec'
import Client from '../editor/plugins/lsp/client' 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 kclLanguage from 'editor/plugins/lsp/kcl/language'
import { copilotPlugin } from 'editor/plugins/lsp/copilot' import { copilotPlugin } from 'editor/plugins/lsp/copilot'
import { useStore } from 'useStore' import { useStore } from 'useStore'
@ -103,7 +103,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
wasmUrl: wasmUrl(), wasmUrl: wasmUrl(),
token: token, token: token,
baseUnit: defaultUnit.current, baseUnit: defaultUnit.current,
devMode: DEV, apiBaseUrl: VITE_KC_API_BASE_URL,
} }
lspWorker.postMessage({ lspWorker.postMessage({
worker: LspWorker.Kcl, worker: LspWorker.Kcl,
@ -177,7 +177,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
const initEvent: CopilotWorkerOptions = { const initEvent: CopilotWorkerOptions = {
wasmUrl: wasmUrl(), wasmUrl: wasmUrl(),
token: token, token: token,
devMode: DEV, apiBaseUrl: VITE_KC_API_BASE_URL,
} }
lspWorker.postMessage({ lspWorker.postMessage({
worker: LspWorker.Copilot, worker: LspWorker.Copilot,

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ async-recursion = "1.1.0"
async-trait = "0.1.80" async-trait = "0.1.80"
base64 = "0.22.0" base64 = "0.22.0"
chrono = "0.4.38" 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" dashmap = "5.5.3"
databake = { version = "0.1.7", features = ["derive"] } databake = { version = "0.1.7", features = ["derive"] }
derive-docs = { version = "0.1.17", path = "../derive-docs" } derive-docs = { version = "0.1.17", path = "../derive-docs" }
@ -24,7 +24,7 @@ form_urlencoded = "1.2.1"
futures = { version = "0.3.30" } futures = { version = "0.3.30" }
git_rev = "0.1.0" git_rev = "0.1.0"
gltf-json = "1.4.0" gltf-json = "1.4.0"
kittycad = { workspace = true } kittycad = { workspace = true, features = ["clap"] }
kittycad-execution-plan-macros = { workspace = true } kittycad-execution-plan-macros = { workspace = true }
kittycad-execution-plan-traits = { workspace = true } kittycad-execution-plan-traits = { workspace = true }
lazy_static = "1.4.0" 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"] } tower-lsp = { version = "0.20.0", features = ["proposed"] }
[features] [features]
default = ["engine"] default = ["cli", "engine"]
cli = ["dep:clap"] cli = ["dep:clap"]
engine = [] engine = []

View File

@ -3,9 +3,23 @@
use std::path::Path; use std::path::Path;
use anyhow::Result; use anyhow::Result;
use clap::ValueEnum;
use crate::settings::types::file::FileEntry; 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. /// Walk a directory recursively and return a list of all files.
#[async_recursion::async_recursion] #[async_recursion::async_recursion]
pub async fn walk_dir<P: AsRef<Path> + Send>(dir: P) -> Result<FileEntry> { 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() { if e.file_type().await?.is_dir() {
children.push(walk_dir(&e.path()).await?); children.push(walk_dir(&e.path()).await?);
} else { } else {
if !is_relevant_file(&e.path())? {
continue;
}
children.push(FileEntry { children.push(FileEntry {
name: e.file_name().to_string_lossy().to_string(), name: e.file_name().to_string_lossy().to_string(),
path: e.path().display().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) 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>, engine_manager: Option<kcl_lib::engine::conn_wasm::EngineCommandManager>,
units: &str, units: &str,
token: String, token: String,
is_dev: bool, baseurl: String,
) -> Result<(), JsValue> { ) -> Result<(), JsValue> {
console_error_panic_hook::set_once(); 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 token_types = kcl_lib::token::TokenType::all_semantic_token_types().unwrap();
let mut zoo_client = kittycad::Client::new(token); let mut zoo_client = kittycad::Client::new(token);
if is_dev { zoo_client.set_base_url(baseurl.as_str());
zoo_client.set_base_url("https://api.dev.zoo.dev");
}
let file_manager = Arc::new(kcl_lib::fs::FileManager::new(fs)); 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 // NOTE: input needs to be an AsyncIterator<Uint8Array, never, void> specifically
#[wasm_bindgen] #[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(); console_error_panic_hook::set_once();
let ServerConfig { let ServerConfig {
@ -323,9 +321,7 @@ pub async fn copilot_lsp_run(config: ServerConfig, token: String, is_dev: bool)
} = config; } = config;
let mut zoo_client = kittycad::Client::new(token); let mut zoo_client = kittycad::Client::new(token);
if is_dev { zoo_client.set_base_url(baseurl.as_str());
zoo_client.set_base_url("https://api.dev.zoo.dev");
}
let file_manager = Arc::new(kcl_lib::fs::FileManager::new(fs)); let file_manager = Arc::new(kcl_lib::fs::FileManager::new(fs));