Skip to content

Commit

Permalink
CodeAction to disable validation
Browse files Browse the repository at this point in the history
See redhat-developer/quarkus-ls#531

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Jan 13, 2022
1 parent ca94e69 commit fb5d9fd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/qute/commands/commandConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ export namespace QuteClientCommandConstants {
export const GENERATE_TEMPLATE_FILE = 'qute.command.generate.template.file';

/**
* Client command to go to the definition of Java data model (field, method, method invokation of "data" method).
* Client command to go to the definition of Java data model (field, method, method invocation of "data" method).
*/
export const JAVA_DEFINTION = 'qute.command.java.definition';

/**
* Client command to update client configuration settings.
*/
export const COMMAND_CONFIGURATION_UPDATE = 'qute.command.configuration.update';

}

/**
Expand Down
52 changes: 51 additions & 1 deletion src/qute/commands/registerCommands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextEncoder } from "util";
import { commands, ExtensionContext, Position, Range, Selection, Uri, window, workspace } from "vscode";
import { commands, ConfigurationTarget, ExtensionContext, Position, Range, Selection, Uri, window, workspace } from "vscode";
import { Location } from "vscode-languageclient";
import { QuteClientCommandConstants, QuteJdtLsServerCommandConstants, QuteServerCommandConstants } from "./commandConstants";

Expand All @@ -12,8 +12,14 @@ export function registerVSCodeQuteCommands(context: ExtensionContext) {
registerOpenUriCommand(context);
registerGenerateTemplateFileCommand(context);
registerJavaDefinitionCommand(context);
registerConfigurationUpdateCommand(context);
}

/**
* Open a Qute template by file Uri.
*
* @param context the extension context.
*/
function registerOpenUriCommand(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand(QuteClientCommandConstants.OPEN_URI, async (uri?: string) => {
commands.executeCommand('vscode.open', Uri.parse(uri));
Expand Down Expand Up @@ -61,3 +67,47 @@ function registerJavaDefinitionCommand(context: ExtensionContext) {
}
}));
}

/**
* Update a given setting from the Qute language server.
*
* @param context the extension context.
*/
export function registerConfigurationUpdateCommand(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand(QuteClientCommandConstants.COMMAND_CONFIGURATION_UPDATE, async (configItemEdit: ConfigurationItemEdit) => {
switch (configItemEdit.editType) {
case ConfigurationItemEditType.Add:
addToPreferenceArray(configItemEdit.section, configItemEdit.value);
break;
case ConfigurationItemEditType.Delete: {
workspace.getConfiguration().update(configItemEdit.section, undefined, ConfigurationTarget.Workspace);
break;
}
case ConfigurationItemEditType.Update: {
workspace.getConfiguration().update(configItemEdit.section, configItemEdit.value, ConfigurationTarget.Workspace);
break;
}
}
}));
}

function addToPreferenceArray<T>(key: string, value: T): void {
const configArray: T[] = workspace.getConfiguration().get<T[]>(key, []);
if (configArray.includes(value)) {
return;
}
configArray.push(value);
workspace.getConfiguration().update(key, configArray, ConfigurationTarget.Workspace);
}

interface ConfigurationItemEdit {
section: string;
value: any;
editType: ConfigurationItemEditType;
}

enum ConfigurationItemEditType {
Add = 0,
Delete = 1,
Update = 2
}
2 changes: 1 addition & 1 deletion src/qute/languageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function connectToQuteLS(context: ExtensionContext) {
valueSet: [
QuteClientCommandConstants.OPEN_URI,
QuteClientCommandConstants.JAVA_DEFINTION,
// CommandKind.COMMAND_OPEN_URI
QuteClientCommandConstants.COMMAND_CONFIGURATION_UPDATE
]
}
},
Expand Down

0 comments on commit fb5d9fd

Please sign in to comment.