Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: Display client/plugin name on API explorer #4801

Merged
merged 8 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions vscode/microsoft-kiota/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,22 +271,22 @@
},
{
"command": "kiota.openApiExplorer.addToSelectedEndpoints",
"when": "view == kiota.openApiExplorer && viewItem != apiTitle",
"when": "view == kiota.openApiExplorer && viewItem != apiTitle && viewItem != clientNameOrPluginName",
"group": "inline@2"
},
{
"command": "kiota.openApiExplorer.addAllToSelectedEndpoints",
"when": "view == kiota.openApiExplorer",
"when": "view == kiota.openApiExplorer && viewItem != clientNameOrPluginName",
"group": "inline@4"
},
{
"command": "kiota.openApiExplorer.removeFromSelectedEndpoints",
"when": "view == kiota.openApiExplorer && viewItem != apiTitle",
"when": "view == kiota.openApiExplorer && viewItem != apiTitle && viewItem != clientNameOrPluginName",
"group": "inline@3"
},
{
"command": "kiota.openApiExplorer.removeAllFromSelectedEndpoints",
"when": "view == kiota.openApiExplorer",
"when": "view == kiota.openApiExplorer && viewItem != clientNameOrPluginName",
"group": "inline@5"
}
],
Expand Down
6 changes: 3 additions & 3 deletions vscode/microsoft-kiota/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export async function activate(
clientOrPluginKey = clientKey;
clientOrPluginObject = clientObject;
workspaceGenerationType = generationType;
await loadEditPaths(clientObject, openApiTreeProvider);
await loadEditPaths(clientOrPluginKey, clientObject, openApiTreeProvider);
ElinorW marked this conversation as resolved.
Show resolved Hide resolved
await vscode.commands.executeCommand('setContext',`${treeViewId}.showIcons`, false);
await vscode.commands.executeCommand('setContext', `${treeViewId}.showRegenerateIcon`, true);
}),
Expand Down Expand Up @@ -579,8 +579,8 @@ async function loadLockFile(node: { fsPath: string }, openApiTreeProvider: OpenA
await vscode.commands.executeCommand('setContext',`${treeViewId}.showIcons`, true);
}

async function loadEditPaths(clientObject: any, openApiTreeProvider: OpenApiTreeProvider): Promise<void> {
await openTreeViewWithProgress(() => openApiTreeProvider.loadEditPaths(clientObject));
async function loadEditPaths(clientOrPluginKey: string, clientObject: any, openApiTreeProvider: OpenApiTreeProvider): Promise<void> {
await openTreeViewWithProgress(() => openApiTreeProvider.loadEditPaths(clientOrPluginKey, clientObject));
}

async function exportLogsAndShowErrors(result: KiotaLogEntry[]) : Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions vscode/microsoft-kiota/src/kiotaInterop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface KiotaOpenApiNode {
selected?: boolean,
isOperation?: boolean;
documentationUrl?: string;
clientNameOrPluginName?: string;
}
interface CacheClearableConfiguration {
clearCache: boolean;
Expand Down
56 changes: 51 additions & 5 deletions vscode/microsoft-kiota/src/openApiTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider<OpenApiTreeN
}
}
}
public async loadEditPaths(clientObject: any): Promise<void> {
public async loadEditPaths(clientOrPluginKey: string, clientObject: any): Promise<void> {
this.closeDescription(false);
this._lockFile = clientObject;
this._lockFile!.clientClassName = clientOrPluginKey;
if (this._lockFile?.descriptionLocation) {
this._descriptionUrl = this._lockFile.descriptionLocation;
this.includeFilters = this._lockFile.includePatterns;
this.excludeFilters = this._lockFile.excludePatterns;
const settings = this.settingsGetter();
await this.loadNodes(settings.clearCache);
await this.loadNodes(settings.clearCache, clientOrPluginKey);
if (this.rawRootNode) {
this.refreshView();
}
Expand Down Expand Up @@ -140,7 +141,15 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider<OpenApiTreeN
}
const segment = segments.shift();
if (segment) {
let child = currentNode.children.find(x => x.segment === segment);
let child: KiotaOpenApiNode | undefined;
if (currentNode.clientNameOrPluginName) {
ElinorW marked this conversation as resolved.
Show resolved Hide resolved
const rootChild = currentNode.children.find(x => x.segment === '/');
if (rootChild) {
child = rootChild.children.find(x => x.segment === segment);
}
} else {
child = currentNode.children.find(x => x.segment === segment);
}
if (child) {
return this.findApiNode(segments, child);
} else if (segment.startsWith('{') && segment.endsWith('}')) {
Expand Down Expand Up @@ -213,7 +222,7 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider<OpenApiTreeN
}
return [];
}
private async loadNodes(clearCache: boolean): Promise<void> {
private async loadNodes(clearCache: boolean, clientNameOrPluginName?: string): Promise<void> {
if (!this.descriptionUrl || this.descriptionUrl.length === 0) {
return;
}
Expand All @@ -233,6 +242,17 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider<OpenApiTreeN
this.setAllSelected(result.rootNode, false);
}
this.rawRootNode = result.rootNode;
if (clientNameOrPluginName) {
this.rawRootNode = createKiotaOpenApiNode(
clientNameOrPluginName,
'/',
[this.rawRootNode],
false,
false,
undefined,
clientNameOrPluginName
);
}
await vscode.commands.executeCommand('setContext',`${treeViewId}.showIcons`, true);
await vscode.commands.executeCommand('setContext', `${treeViewId}.showRegenerateIcon`, false);
}
Expand All @@ -256,6 +276,7 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider<OpenApiTreeN
this.apiTitle,
node.children.map(x => this.getTreeNodeFromKiotaNode(x)),
node.documentationUrl,
node.clientNameOrPluginName
);
}
getChildren(element?: OpenApiTreeNode): vscode.ProviderResult<OpenApiTreeNode[]> {
Expand All @@ -279,6 +300,26 @@ function getPathSegments(path: string): string[] {
function trimOperation(path: string): string {
return path.split(operationSeparator)[0];
}

function createKiotaOpenApiNode(
segment: string,
path: string,
children: KiotaOpenApiNode[] = [],
selected?: boolean,
isOperation?: boolean,
documentationUrl?: string,
clientNameOrPluginName?: string
): KiotaOpenApiNode {
return {
segment,
path,
children,
selected,
isOperation,
documentationUrl,
clientNameOrPluginName
};
}
type IconSet = string | vscode.Uri | { light: string | vscode.Uri; dark: string | vscode.Uri } | vscode.ThemeIcon;
export class OpenApiTreeNode extends vscode.TreeItem {
private static readonly selectedSet: IconSet = new vscode.ThemeIcon('check');
Expand All @@ -293,12 +334,17 @@ export class OpenApiTreeNode extends vscode.TreeItem {
filterTokens: string[],
apiTitle: string | undefined,
public readonly children: OpenApiTreeNode[] = [],
public readonly documentationUrl?: string
public readonly documentationUrl?: string,
public readonly clientNameOrPluginName?: string
) {
super(label, collapsibleState);
this.id = `${path}_${filterTokens.join('_')}`; // so the collapsed state is NOT persisted between filter changes
this.contextValue = label === pathSeparator + " (" + apiTitle + ")" ? 'apiTitle' : (this.documentationUrl ? 'documentationUrl' : '');
this.iconPath = selected ? OpenApiTreeNode.selectedSet : OpenApiTreeNode.unselectedSet;
if(clientNameOrPluginName) {
this.label = clientNameOrPluginName;
this.contextValue = 'clientNameOrPluginName';
}
}
public isNodeVisible(tokenizedFilter: string[]): boolean {
if (tokenizedFilter.length === 0) {
Expand Down
Loading