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

Feature: Add tooltips to find #2174

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 11 additions & 1 deletion src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import tmp from 'tmp';
import util from 'util';
import { MarkdownString, window } from 'vscode';
import { ObjectTypes } from '../filesystems/qsys/Objects';
import { AttrOperands, CommandResult, IBMiError, IBMiMember, IBMiObject, IFSFile, QsysPath } from '../typings';
import { AttrOperands, CommandResult, IBMiError, IBMiMember, IBMiObject, IFSFile, QsysPath, SearchHit } from '../typings';
import { ConnectionConfiguration } from './Configuration';
import { FilterType, parseFilter, singleGenericName } from './Filter';
import { default as IBMi } from './IBMi';
Expand Down Expand Up @@ -1021,4 +1021,14 @@ export default class IBMiContent {
tooltip.supportHtml = true;
return tooltip;
}

searchHitToToolTip(path: string, hit: SearchHit) {
const tooltip = new MarkdownString(Tools.generateTooltipHtmlTable(path, {
size: hit.size,
modified: hit.modified ? new Date(hit.modified.getTime() - hit.modified.getTimezoneOffset() * 60 * 1000).toISOString().slice(0, 19).replace(`T`, ` `) : ``,
owner: hit.owner ? hit.owner.toUpperCase() : ``
}));
tooltip.supportHtml = true;
return tooltip;
}
}
24 changes: 19 additions & 5 deletions src/api/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export namespace Search {
const connection = instance.getConnection();
if (connection) {
const find = connection.remoteFeatures.find;
const stat = connection.remoteFeatures.stat;

if (find) {
const dirsToIgnore = GlobalConfiguration.get<string[]>(`grepIgnoreDirs`) || [];
Expand All @@ -92,14 +93,15 @@ export namespace Search {
ignoreString = dirsToIgnore.map(dir => `-type d -path '*/${dir}' -prune -o`).join(` `);
}

const findExec = stat ? `-exec ${stat} --printf="%U\t%s\t%Y\t%n\n" {} +` : `-print`;
const findRes = await connection.sendCommand({
command: `${find} ${Tools.escapePath(path)} ${ignoreString} -type f -iname '*${findTerm}*' -print`
command: `${find} ${Tools.escapePath(path)} ${ignoreString} -type f -iname '*${findTerm}*' ${findExec}`
});

if (findRes.code == 0 && findRes.stdout) {
return {
term: findTerm,
hits: parseFindOutput(findRes.stdout)
hits: parseFindOutput(findRes.stdout, undefined, (stat !== undefined))
}
}
} else {
Expand All @@ -111,11 +113,23 @@ export namespace Search {
}
}

function parseFindOutput(output: string, readonly?: boolean, pathTransformer?: (path: string) => string): SearchHit[] {
function parseFindOutput(output: string, readonly?: boolean, statOutput?: boolean, pathTransformer?: (path: string) => string): SearchHit[] {
const results: SearchHit[] = [];
for (const line of output.split('\n')) {
const path = pathTransformer?.(line) || line;
results.push(results.find(r => r.path === path) || { path, readonly, lines: [] });
if (statOutput) {
let owner: string, size: string, modified: string, name: string;
[owner, size, modified, name] = line.split(`\t`);
results.push({
path: name,
lines: [],
size: Number(size),
modified: new Date(Number(modified) * 1000),
owner: owner
});
} else {
const path = pathTransformer?.(line) || line;
results.push(results.find(r => r.path === path) || { path, readonly, lines: [] });
}
}
return results;
}
Expand Down
3 changes: 3 additions & 0 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ export type SearchHit = {
lines: SearchHitLine[]
readonly?: boolean
label?: string
size?: Number
modified?: Date
owner?: string
}

export type SearchHitLine = {
Expand Down
5 changes: 3 additions & 2 deletions src/views/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vscode from "vscode";
import { DefaultOpenMode } from "../api/Configuration";
import { t } from '../locale';
import { SearchHit, SearchHitLine, SearchResults } from "../typings";
import { instance } from "../instantiate";

export function initializeSearchView(context: vscode.ExtensionContext) {
const searchView = new SearchView();
Expand Down Expand Up @@ -80,13 +81,13 @@ class HitSource extends vscode.TreeItem {
this.iconPath = vscode.ThemeIcon.File;
this.path = result.path;
this._readonly = result.readonly;
this.tooltip = result.path;
this.tooltip = instance.getContent()?.searchHitToToolTip(this.path, result);

if (hits) {
this.description = `${hits} hit${hits === 1 ? `` : `s`}`;
}
else {
this.description = result.path;
this.description = !result.size ? result.path : ``;
this.command = {
command: `code-for-ibmi.openWithDefaultMode`,
title: `Open`,
Expand Down