Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,11 @@
"command": "vscode-objectscript.ccs.createItem",
"group": "6_create@1",
"when": "editorTextFocus && editorLangId =~ /^objectscript/"
},
{
"command": "vscode-objectscript.ccs.atualizarConfiguracoes",
"group": "7_config@1",
"when": "vscode-objectscript.connectActive"
}
]
},
Expand Down Expand Up @@ -1360,6 +1365,11 @@
"command": "vscode-objectscript.ccs.analizarVersaoItem",
"title": "Versões do Item - Analizar"
},
{
"category": "Consistem",
"command": "vscode-objectscript.ccs.atualizarConfiguracoes",
"title": "Atualizar Configurações"
},
{
"category": "ObjectScript",
"command": "vscode-objectscript.compileWithFlags",
Expand Down
33 changes: 33 additions & 0 deletions src/ccs/commands/atualizarConfiguracoes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as vscode from "vscode";

import { handleError, outputChannel } from "../../utils";
import { AtualizarConfigClient } from "../sourcecontrol/clients/atualizarConfigClient";

const sharedClient = new AtualizarConfigClient();

export async function atualizarConfiguracoes(): Promise<void> {
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Atualizando configurações...",
cancellable: false,
},
async () => {
try {
const responseText = await sharedClient.atualizarConfig();
renderOutput(responseText);
} catch (error) {
handleError(error, "Falha ao atualizar configurações.");
}
}
);
}

function renderOutput(responseText: string): void {
responseText
.split(/\r?\n/)
.filter((line) => line.length > 0)
.forEach((line) => outputChannel.appendLine(line));

outputChannel.show(true);
}
1 change: 1 addition & 0 deletions src/ccs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export { createItem } from "./commands/createItem";

export { convertCurrentItem, convertCurrentItemCustom, convertCurrentItemOnSave } from "./commands/converterItem";
export { analizarVersaoItem } from "./commands/analizarVersaoItem";
export { atualizarConfiguracoes } from "./commands/atualizarConfiguracoes";
63 changes: 63 additions & 0 deletions src/ccs/sourcecontrol/clients/atualizarConfigClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as vscode from "vscode";

import { AtelierAPI } from "../../../api";
import { createAbortSignal } from "../../core/http";
import { logDebug } from "../../core/logging";
import { SourceControlApi } from "../client";
import { ROUTES } from "../routes";

const DESENV_NS_PATTERN = /^DESENV\d+$/i;

export class AtualizarConfigClient {
private readonly apiFactory: (api: AtelierAPI) => SourceControlApi;

public constructor(apiFactory: (api: AtelierAPI) => SourceControlApi = SourceControlApi.fromAtelierApi) {
this.apiFactory = apiFactory;
}

public async atualizarConfig(): Promise<string> {
const api = this.resolveDesenvApi();

let sourceControlApi: SourceControlApi;
try {
sourceControlApi = this.apiFactory(api);
} catch (error) {
logDebug("Failed to create SourceControl API client para atualizarConfig", error);
throw error;
}

const { signal, dispose } = createAbortSignal();

try {
const response = await sourceControlApi.post<string>(
ROUTES.atualizarConfig(api.ns),
{},
{
timeout: 0,
signal,
responseType: "text",
transformResponse: (data) => data,
validateStatus: (status) => status >= 200 && status < 300,
}
);

return typeof response.data === "string" ? response.data : "";
} catch (error) {
logDebug("atualizarConfig request failed", error);
throw error;
} finally {
dispose();
}
}

private resolveDesenvApi(): AtelierAPI {
for (const wsFolder of vscode.workspace.workspaceFolders ?? []) {
if (!DESENV_NS_PATTERN.test(wsFolder.name)) continue;
const api = new AtelierAPI(wsFolder.uri);
if (!api.active) continue;
return api;
}

throw new Error("Namespace DESENVXX não encontrado. Verifique as configurações do workspace.");
}
}
1 change: 1 addition & 0 deletions src/ccs/sourcecontrol/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const ROUTES = {
converterArquivoCustomizado: (namespace: string) =>
`/namespaces/${encodeURIComponent(namespace)}/converterArquivoCustomizado`,
analizarVersaoItem: (namespace: string) => `/namespaces/${encodeURIComponent(namespace)}/analizarVersaoItem`,
atualizarConfig: (namespace: string) => `/namespaces/${encodeURIComponent(namespace)}/atualizarConfig`,
} as const;

export type RouteKey = keyof typeof ROUTES;
5 changes: 5 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ import {
convertCurrentItemCustom,
convertCurrentItemOnSave,
analizarVersaoItem,
atualizarConfiguracoes,
} from "./ccs";

const packageJson = vscode.extensions.getExtension(extensionId).packageJSON;
Expand Down Expand Up @@ -1441,6 +1442,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
sendCommandTelemetryEvent("analizarVersaoItem");
void analizarVersaoItem();
}),
vscode.commands.registerCommand("vscode-objectscript.ccs.atualizarConfiguracoes", () => {
sendCommandTelemetryEvent("atualizarConfiguracoes");
void atualizarConfiguracoes();
}),
vscode.commands.registerCommand("vscode-objectscript.serverCommands.sourceControl", (uri?: vscode.Uri) => {
sendCommandTelemetryEvent("serverCommands.sourceControl");
mainSourceControlMenu(uri);
Expand Down