Skip to content

Commit 8107e5a

Browse files
committed
add new method to js bindings
1 parent 688e5d2 commit 8107e5a

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

crates/pgt_workspace/src/workspace.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use pgt_analyse::RuleCategories;
55
use pgt_configuration::{PartialConfiguration, RuleSelector};
66
use pgt_fs::PgTPath;
77
use pgt_text_size::TextRange;
8+
#[cfg(feature = "schema")]
9+
use schemars::{JsonSchema, SchemaGenerator, schema::Schema};
810
use serde::{Deserialize, Serialize};
911
use slotmap::{DenseSlotMap, new_key_type};
1012

@@ -255,6 +257,17 @@ new_key_type! {
255257
pub struct ProjectKey;
256258
}
257259

260+
#[cfg(feature = "schema")]
261+
impl JsonSchema for ProjectKey {
262+
fn schema_name() -> String {
263+
"ProjectKey".to_string()
264+
}
265+
266+
fn json_schema(generator: &mut SchemaGenerator) -> Schema {
267+
<String>::json_schema(generator)
268+
}
269+
}
270+
258271
#[derive(Debug, Default)]
259272
pub struct WorkspaceData<V> {
260273
/// [DenseSlotMap] is the slowest type in insertion/removal, but the fastest in iteration

crates/pgt_workspace/src/workspace_types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,10 @@ macro_rules! workspace_method {
457457
}
458458

459459
/// Returns a list of signature for all the methods in the [Workspace] trait
460-
pub fn methods() -> [WorkspaceMethod; 8] {
460+
pub fn methods() -> [WorkspaceMethod; 9] {
461461
[
462462
workspace_method!(is_path_ignored),
463+
workspace_method!(register_project_folder),
463464
workspace_method!(get_file_content),
464465
workspace_method!(pull_diagnostics),
465466
workspace_method!(get_completions),

packages/@postgrestools/backend-jsonrpc/src/workspace.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export type FileKind = FileKind2[];
1919
* The priority of the file
2020
*/
2121
export type FileKind2 = "Config" | "Ignore" | "Inspectable" | "Handleable";
22+
export interface RegisterProjectFolderParams {
23+
path?: string;
24+
setAsCurrentWorkspace: boolean;
25+
}
26+
export type ProjectKey = string;
2227
export interface GetFileContentParams {
2328
path: PgTPath;
2429
}
@@ -92,7 +97,7 @@ export type DiagnosticTags = DiagnosticTag[];
9297
/**
9398
* Serializable representation of a [Diagnostic](super::Diagnostic) advice
9499
95-
See the [Visitor] trait for additional documentation on all the supported advice types.
100+
See the [Visitor] trait for additional documentation on all the supported advice types.
96101
*/
97102
export type Advice =
98103
| { log: [LogCategory, MarkupBuf] }
@@ -197,7 +202,7 @@ export interface CompletionItem {
197202
/**
198203
* The text that the editor should fill in. If `None`, the `label` should be used. Tables, for example, might have different completion_texts:
199204
200-
label: "users", description: "Schema: auth", completion_text: "auth.users".
205+
label: "users", description: "Schema: auth", completion_text: "auth.users".
201206
*/
202207
export interface CompletionText {
203208
is_snippet: boolean;
@@ -350,7 +355,7 @@ export interface PartialVcsConfiguration {
350355
/**
351356
* The folder where we should check for VCS files. By default, we will use the same folder where `postgrestools.jsonc` was found.
352357
353-
If we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted
358+
If we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted
354359
*/
355360
root?: string;
356361
/**
@@ -436,6 +441,9 @@ export interface CloseFileParams {
436441
export type Configuration = PartialConfiguration;
437442
export interface Workspace {
438443
isPathIgnored(params: IsPathIgnoredParams): Promise<boolean>;
444+
registerProjectFolder(
445+
params: RegisterProjectFolderParams,
446+
): Promise<ProjectKey>;
439447
getFileContent(params: GetFileContentParams): Promise<string>;
440448
pullDiagnostics(
441449
params: PullDiagnosticsParams,
@@ -452,6 +460,9 @@ export function createWorkspace(transport: Transport): Workspace {
452460
isPathIgnored(params) {
453461
return transport.request("pgt/is_path_ignored", params);
454462
},
463+
registerProjectFolder(params) {
464+
return transport.request("pgt/register_project_folder", params);
465+
},
455466
getFileContent(params) {
456467
return transport.request("pgt/get_file_content", params);
457468
},

packages/@postgrestools/backend-jsonrpc/tests/workspace.test.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { resolve } from "node:path";
22
import { fileURLToPath } from "node:url";
33
import { describe, expect, it } from "vitest";
44

5-
import { createWorkspaceWithBinary } from "../dist";
5+
import { createWorkspaceWithBinary } from "../src";
66

77
describe("Workspace API", () => {
88
it("should process remote requests", async () => {
@@ -14,6 +14,9 @@ describe("Workspace API", () => {
1414
);
1515

1616
const workspace = await createWorkspaceWithBinary(command);
17+
workspace.registerProjectFolder({
18+
setAsCurrentWorkspace: true,
19+
});
1720
await workspace.openFile({
1821
path: {
1922
path: "test.sql",

0 commit comments

Comments
 (0)