Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
sawka committed Feb 3, 2025
2 parents fbb2e77 + fc298f2 commit 7d921ea
Show file tree
Hide file tree
Showing 40 changed files with 1,753 additions and 771 deletions.
22 changes: 22 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ tasks:
- task: build:server
- task: build:wsh

build:schema:
desc: Build the schema for configuration.
sources:
- "cmd/generateschema/*.go"
- "pkg/wconfig/*.go"
generates:
- "dist/schema/**/*"
cmds:
- go run cmd/generateschema/main-generateschema.go
- '{{.RMRF}} "dist/schema"'
- task: copyfiles:'schema':'dist/schema'

build:server:
desc: Build the wavesrv component.
cmds:
Expand Down Expand Up @@ -199,6 +211,14 @@ tasks:
vars:
GOOS: linux
GOARCH: amd64
- task: build:wsh:internal
vars:
GOOS: linux
GOARCH: mips
- task: build:wsh:internal
vars:
GOOS: linux
GOARCH: mips64
- task: build:wsh:internal
vars:
GOOS: windows
Expand Down Expand Up @@ -235,6 +255,8 @@ tasks:
cmds:
- go run cmd/generatets/main-generatets.go
- go run cmd/generatego/main-generatego.go
deps:
- build:schema
sources:
- "cmd/generatego/*.go"
- "cmd/generatets/*.go"
Expand Down
1 change: 1 addition & 0 deletions cmd/generatego/main-generatego.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func GenerateWshClient() error {
"github.com/wavetermdev/waveterm/pkg/waveobj",
"github.com/wavetermdev/waveterm/pkg/wps",
"github.com/wavetermdev/waveterm/pkg/vdom",
"github.com/wavetermdev/waveterm/pkg/util/iochan/iochantypes",
})
wshDeclMap := wshrpc.GenerateWshCommandDeclMap()
for _, key := range utilfn.GetOrderedMapKeys(wshDeclMap) {
Expand Down
39 changes: 39 additions & 0 deletions cmd/generateschema/main-generateschema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package main

import (
"encoding/json"
"fmt"
"log"
"os"

"github.com/invopop/jsonschema"
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
"github.com/wavetermdev/waveterm/pkg/wconfig"
)

const WaveSchemaSettingsFileName = "schema/settings.json"

func main() {
settingsSchema := jsonschema.Reflect(&wconfig.SettingsType{})

jsonSettingsSchema, err := json.MarshalIndent(settingsSchema, "", " ")
if err != nil {
log.Fatalf("failed to parse local schema: %v", err)
}
/*
err = os.MkdirAll(WaveSchemaSettingsFileName, 0755)
if err != nil {
log.Fatalf("failed to create schema dir: %v", err)
}
*/
written, err := utilfn.WriteFileIfDifferent(WaveSchemaSettingsFileName, jsonSettingsSchema)
if !written {
fmt.Fprintf(os.Stderr, "no changes to %s\n", WaveSchemaSettingsFileName)
}
if err != nil {
log.Fatalf("failed to write local schema: %v", err)
}
}
7 changes: 6 additions & 1 deletion cmd/wsh/cmd/wshcmd-file.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func init() {
fileCmd.AddCommand(fileListCmd)
fileCmd.AddCommand(fileCatCmd)
fileCmd.AddCommand(fileWriteCmd)
fileRmCmd.Flags().BoolP("recursive", "r", false, "remove directories recursively")
fileCmd.AddCommand(fileRmCmd)
fileCmd.AddCommand(fileInfoCmd)
fileCmd.AddCommand(fileAppendCmd)
Expand Down Expand Up @@ -259,6 +260,10 @@ func fileRmRun(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
recursive, err := cmd.Flags().GetBool("recursive")
if err != nil {
return err
}
fileData := wshrpc.FileData{
Info: &wshrpc.FileInfo{
Path: path}}
Expand All @@ -272,7 +277,7 @@ func fileRmRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("getting file info: %w", err)
}

err = wshclient.FileDeleteCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: DefaultFileTimeout})
err = wshclient.FileDeleteCommand(RpcClient, wshrpc.CommandDeleteFileData{Path: path, Recursive: recursive}, &wshrpc.RpcOpts{Timeout: DefaultFileTimeout})
if err != nil {
return fmt.Errorf("removing file: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
"@docusaurus/module-type-aliases": "3.7.0",
"@docusaurus/tsconfig": "3.7.0",
"@docusaurus/types": "3.7.0",
"@eslint/js": "^9.18.0",
"@eslint/js": "^9.19.0",
"@mdx-js/typescript-plugin": "^0.0.8",
"@types/eslint": "^9.6.1",
"@types/eslint-config-prettier": "^6.11.3",
"@types/ua-parser-js": "^0.7.39",
"eslint": "^9.18.0",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-mdx": "^3.1.5",
"prettier": "^3.4.2",
Expand All @@ -54,10 +54,10 @@
"remark-cli": "^12.0.1",
"remark-frontmatter": "^5.0.0",
"remark-mdx": "^3.1.0",
"remark-preset-lint-consistent": "^6.0.0",
"remark-preset-lint-recommended": "^7.0.0",
"remark-preset-lint-consistent": "^6.0.1",
"remark-preset-lint-recommended": "^7.0.1",
"typescript": "^5.7.3",
"typescript-eslint": "^8.21.0"
"typescript-eslint": "^8.22.0"
},
"resolutions": {
"path-to-regexp@npm:2.2.1": "^3",
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/store/wshclientapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class RpcApiType {
}

// command "filedelete" [call]
FileDeleteCommand(client: WshClient, data: FileData, opts?: RpcOpts): Promise<void> {
FileDeleteCommand(client: WshClient, data: CommandDeleteFileData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("filedelete", data, opts);
}

Expand Down Expand Up @@ -203,7 +203,7 @@ class RpcApiType {
}

// command "filestreamtar" [responsestream]
FileStreamTarCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<string, void, boolean> {
FileStreamTarCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<Packet, void, boolean> {
return client.wshRpcStream("filestreamtar", data, opts);
}

Expand Down Expand Up @@ -263,7 +263,7 @@ class RpcApiType {
}

// command "remotefiledelete" [call]
RemoteFileDeleteCommand(client: WshClient, data: string, opts?: RpcOpts): Promise<void> {
RemoteFileDeleteCommand(client: WshClient, data: CommandDeleteFileData, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("remotefiledelete", data, opts);
}

Expand Down Expand Up @@ -318,7 +318,7 @@ class RpcApiType {
}

// command "remotetarstream" [responsestream]
RemoteTarStreamCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<string, void, boolean> {
RemoteTarStreamCommand(client: WshClient, data: CommandRemoteStreamTarData, opts?: RpcOpts): AsyncGenerator<Packet, void, boolean> {
return client.wshRpcStream("remotetarstream", data, opts);
}

Expand Down
104 changes: 62 additions & 42 deletions frontend/app/view/codeeditor/codeeditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import type * as MonacoTypes from "monaco-editor/esm/vs/editor/editor.api";
import { configureMonacoYaml } from "monaco-yaml";
import React, { useMemo, useRef } from "react";

import { RpcApi } from "@/app/store/wshclientapi";
import { TabRpcClient } from "@/app/store/wshrpcutil";
import { makeConnRoute } from "@/util/util";
import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
import cssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker";
import htmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker";
import jsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker";
import tsWorker from "monaco-editor/esm/vs/language/typescript/ts.worker?worker";
import { SchemaEndpoints, getSchemaEndpointInfo } from "./schemaendpoints";
import ymlWorker from "./yamlworker?worker";

import "./codeeditor.scss";
Expand Down Expand Up @@ -42,48 +46,45 @@ window.MonacoEnvironment = {
},
};

export function loadMonaco() {
export async function loadMonaco() {
loader.config({ paths: { vs: "monaco" } });
loader
.init()
.then(() => {
monaco.editor.defineTheme("wave-theme-dark", {
base: "vs-dark",
inherit: true,
rules: [],
colors: {
"editor.background": "#00000000",
"editorStickyScroll.background": "#00000055",
"minimap.background": "#00000077",
focusBorder: "#00000000",
},
});
monaco.editor.defineTheme("wave-theme-light", {
base: "vs",
inherit: true,
rules: [],
colors: {
"editor.background": "#fefefe",
focusBorder: "#00000000",
},
});
configureMonacoYaml(monaco, {
validate: true,
schemas: [],
});
// Disable default validation errors for typescript and javascript
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: true,
});
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
allowComments: false, // Set to true if you want to allow comments in JSON
schemas: [], // You can specify JSON schemas here if needed
});
})
.catch((e) => {
console.error("error loading monaco", e);
});
await loader.init();

monaco.editor.defineTheme("wave-theme-dark", {
base: "vs-dark",
inherit: true,
rules: [],
colors: {
"editor.background": "#00000000",
"editorStickyScroll.background": "#00000055",
"minimap.background": "#00000077",
focusBorder: "#00000000",
},
});
monaco.editor.defineTheme("wave-theme-light", {
base: "vs",
inherit: true,
rules: [],
colors: {
"editor.background": "#fefefe",
focusBorder: "#00000000",
},
});
configureMonacoYaml(monaco, {
validate: true,
schemas: [],
});
// Disable default validation errors for typescript and javascript
monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
noSemanticValidation: true,
});
const schemas = await Promise.all(SchemaEndpoints.map((endpoint) => getSchemaEndpointInfo(endpoint)));
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
allowComments: false, // Set to true if you want to allow comments in JSON
enableSchemaRequest: true,
schemas,
});
}

function defaultEditorOptions(): MonacoTypes.editor.IEditorOptions {
Expand Down Expand Up @@ -125,6 +126,7 @@ export function CodeEditor({ blockId, text, language, filename, meta, onChange,
const wordWrap = useOverrideConfigAtom(blockId, "editor:wordwrap") ?? false;
const fontSize = boundNumber(useOverrideConfigAtom(blockId, "editor:fontsize"), 6, 64);
const theme = "wave-theme-dark";
const [absPath, setAbsPath] = React.useState("");

React.useEffect(() => {
return () => {
Expand All @@ -135,6 +137,24 @@ export function CodeEditor({ blockId, text, language, filename, meta, onChange,
};
}, []);

React.useEffect(() => {
const inner = async () => {
try {
const fileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [filename], {
route: makeConnRoute(meta.connection ?? ""),
});
setAbsPath(`${fileInfo.dir}/${fileInfo.name}`);
} catch (e) {
setAbsPath(filename);
}
};
inner();
}, [filename]);

React.useEffect(() => {
console.log("abspath is", absPath);
}, [absPath]);

function handleEditorChange(text: string, ev: MonacoTypes.editor.IModelContentChangedEvent) {
if (onChange) {
onChange(text);
Expand Down Expand Up @@ -165,7 +185,7 @@ export function CodeEditor({ blockId, text, language, filename, meta, onChange,
options={editorOpts}
onChange={handleEditorChange}
onMount={handleEditorOnMount}
path={filename}
path={absPath}
language={language}
/>
</div>
Expand Down
38 changes: 38 additions & 0 deletions frontend/app/view/codeeditor/schemaendpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

import { getApi } from "@/app/store/global";
import { getWebServerEndpoint } from "@/util/endpoints";

type EndpointInfo = {
uri: string;
fileMatch: Array<string>;
schema: object;
};

const allFilepaths: Map<string, Array<string>> = new Map();
allFilepaths.set(`${getWebServerEndpoint()}/schema/settings.json`, [`${getApi().getConfigDir()}/settings.json`]);

async function getSchemaEndpointInfo(endpoint: string): Promise<EndpointInfo> {
let schema: Object;
try {
const data = await fetch(endpoint);
const fullSchema: object = await data.json();
const schemaRef: string = fullSchema?.["$ref"];
schema = fullSchema?.[schemaRef];
} catch (e) {
console.log("cannot find schema:", e);
schema = {};
}
const fileMatch = allFilepaths.get(endpoint) ?? [];

return {
uri: endpoint,
fileMatch,
schema,
};
}

const SchemaEndpoints = Array.from(allFilepaths.keys());

export { getSchemaEndpointInfo, SchemaEndpoints };
Loading

0 comments on commit 7d921ea

Please sign in to comment.