Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
FUSETOOLS2-2164 - get rid of internal dependency to kamel help trait
Browse files Browse the repository at this point in the history
Remove completion for traits in VS Code tasks.json. This will be now
provided by the VS Code Language Support for Camel extension. It allows
to get rid of internal dependency to `kamel help trait` which is removed
from kamel 2.x.

Signed-off-by: Aurélien Pupier <[email protected]>
  • Loading branch information
apupier committed Sep 18, 2023
1 parent 984d2d6 commit e3ccb09
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 266 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to the "vscode-camelk" extension will be documented in this
## 0.0.35

- Remove `Create Integration file` command, in favor of `Camel: Create Camel Route in xxx DSL` provided by VS Code Language Support for Apache Camel. It allows also to get rid of internal dependency to `kamel init` which is removed from kamel 2.x.
- Remove completion for traits in VS Code tasks.json. This will be now provided by the VS Code Language Support for Camel extension. It allows also to get rid of internal dependency to `kamel help trait` which is removed from kamel 2.x.

## 0.0.34

Expand Down
34 changes: 3 additions & 31 deletions src/task/CamelKTaskCompletionItemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@

import * as jsonparser from 'jsonc-parser';
import * as vscode from 'vscode';
import { TraitManager } from './TraitManager';

export class CamelKTaskCompletionItemProvider implements vscode.CompletionItemProvider {

provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
return this.provideCompletionItemsForText(document.getText(), document.offsetAt(position), position);
return this.provideCompletionItemsForText(document.getText(), document.offsetAt(position));
}

public async provideCompletionItemsForText(text: string, offset: number, position: vscode.Position): Promise<vscode.CompletionItem[]> {
public async provideCompletionItemsForText(text: string, offset: number): Promise<vscode.CompletionItem[]> {
const globalNode = jsonparser.parseTree(text);
let completions: vscode.CompletionItem[] = [];
const completions: vscode.CompletionItem[] = [];
if(globalNode !== undefined) {
const node = jsonparser.findNodeAtOffset(globalNode, offset, false);
if (node) {
Expand All @@ -45,35 +44,12 @@ export class CamelKTaskCompletionItemProvider implements vscode.CompletionItemPr
}`
};
completions.push(completionBasic);
} else if (this.isInTraitsArray(node)) {
const traitCompletions: vscode.CompletionItem[] = await TraitManager.provideAvailableTraits();
completions = completions.concat(traitCompletions);
} else if (this.isInTraitsArrayMember(node)) {
const value = node.value as string;
const traitpropertyCompletions: vscode.CompletionItem[] = await TraitManager.provideTraitProperties(value.substr(0, value.length - 1), position);
completions = completions.concat(traitpropertyCompletions);
}
}
}
return Promise.resolve(completions);
}

private isInTraitsArray(node: jsonparser.Node) {
return this.isInArray(node)
&& this.isSiblingTraitTasks(node);
}

private isInTraitsArrayMember(node: jsonparser.Node) {
const parent = node.parent;
if (parent && this.isInTraitsArray(parent) && node.type === "string") {
const value = node.value as string;
if (value && value.endsWith('.')) {
return true;
}
}
return false;
}

private isParentHasStringPropertyOfType(node: jsonparser.Node, type: string) {
const parent = node.parent;
if (parent !== undefined && parent.type === "property") {
Expand All @@ -85,10 +61,6 @@ export class CamelKTaskCompletionItemProvider implements vscode.CompletionItemPr
return false;
}

private isSiblingTraitTasks(node: jsonparser.Node) {
return this.isParentHasStringPropertyOfType(node, 'traits');
}

private isInTasksArray(node: jsonparser.Node) {
return this.isInArray(node)
&& this.isParentTasks(node);
Expand Down
27 changes: 0 additions & 27 deletions src/task/TraitDefinition.ts

This file was deleted.

86 changes: 0 additions & 86 deletions src/task/TraitManager.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/task/TraitProperty.ts

This file was deleted.

86 changes: 0 additions & 86 deletions src/test/suite/CamelKTaskCompletionItemProvider.test.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/suite/_completion/completion.tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ suite('Should do completion in tasks.json', () => {
await testCompletion(docURiTasksJson, new vscode.Position(3, 7), expectedCompletion);
});

const testTraits = test('Completes for traits', async () => {
skipOnJenkins(testTraits);
const expectedCompletion = { label: 'platform', documentation: `The platform trait is a base trait that is used to assign an integration platform to an integration. In case the platform is missing, the trait is allowed to create a default platform. This feature is especially useful in contexts where there's no need to provide a custom configuration for the platform (e.g. on OpenShift the default settings work, since there's an embedded container image registry).` };
await testCompletion(docURiTasksJson, new vscode.Position(9, 23), expectedCompletion);
});

const testTraitProperties = test('Completes for trait properties', async () => {
skipOnJenkins(testTraitProperties);
const expectedCompletion = { label: 'enabled', insertText: 'enabled=false', documentation: 'Can be used to enable or disable a trait. All traits share this common property.' };
await testCompletion(docURiTasksJson, new vscode.Position(17, 33), expectedCompletion);
});

});

async function testCompletion(
Expand Down

0 comments on commit e3ccb09

Please sign in to comment.