Skip to content

Commit

Permalink
Merge pull request #2529 from BetterThanTomorrow/2524-reindent-inspec…
Browse files Browse the repository at this point in the history
…tor-item

2524 reindent inspector item
  • Loading branch information
PEZ authored Apr 21, 2024
2 parents c8b0997 + 4352603 commit 28663c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- [Re-indent text when copied from the inspector as well as tooltips](https://github.com/BetterThanTomorrow/calva/issues/2524)

## [2.0.445] - 2024-04-21

- [Make list items in the inspector get a bit easier to read](https://github.com/BetterThanTomorrow/calva/issues/2521)
Expand Down
4 changes: 3 additions & 1 deletion src/cljs-lib/src/calva/pprint/printer.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@


(defn pretty-print-js [s {:keys [maxLength, maxDepth, map-commas?] :as all-opts}]
(println "all-opts" all-opts)
(let [opts (into {}
(remove (comp nil? val)
(-> all-opts
(dissoc :maxLength :maxDepth :printEngine :enabled :map-commas?)
(update :style (partial mapv keyword))
(merge {:max-length maxLength
:max-depth maxDepth}))))
opts (if (nil? map-commas?)
opts
(assoc opts :map {:comma? map-commas?}))]
(assoc-in opts [:map :comma?] map-commas?))]
(jsify (pretty-print s opts))))

(defn ^:export pretty-print-js-bridge [s ^js opts]
Expand Down
29 changes: 24 additions & 5 deletions src/providers/inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export class InspectorDataProvider implements vscode.TreeDataProvider<InspectorI
element: InspectorItem,
token: vscode.CancellationToken
): vscode.ProviderResult<vscode.TreeItem> {
const prettyString: string = prettifiedOriginalString(item);
item.tooltip = new vscode.MarkdownString(
(item.info ? item.info + '\n' : '') +
'```clojure\n' +
prettyString.substring(0, 10000) +
'\n```'
);
return item;
}

Expand Down Expand Up @@ -148,8 +155,19 @@ export class InspectorDataProvider implements vscode.TreeDataProvider<InspectorI
}
}

function prettifiedOriginalString(item: InspectorItem) {
const printerOptions = {
...printer.prettyPrintingOptions(),
width: 80,
style: ['community', 'justified'],
map: { 'sort?': false, 'comma?': false },
};
const result = printer.prettyPrint(item.originalString, printerOptions);
return result?.value || item.originalString;
}

export const copyItemValue = async (item: InspectorItem) => {
await vscode.env.clipboard.writeText(item.originalString);
await vscode.env.clipboard.writeText(prettifiedOriginalString(item));
};

export async function pasteFromClipboard() {
Expand Down Expand Up @@ -194,7 +212,11 @@ export function createTreeStructure(item: InspectorItem) {
const startTime = performance.now();

const prettyPrintStartTime = performance.now();
const printerOptions = printer.prettyPrintingOptions();
const printerOptions = {
...printer.prettyPrintingOptions(),
width: 500,
map: { 'sort?': false, 'commas?': false },
};
const firstLineLength = originalString.split('\n')[0].length;
const needPrettyPrint = firstLineLength > 10000;
const prettyString = needPrettyPrint
Expand Down Expand Up @@ -297,9 +319,6 @@ class InspectorItem extends vscode.TreeItem {
this.originalString = originalString;
this.info = info;
this.children = children;
this.tooltip = new vscode.MarkdownString(
(info ? info + '\n' : '') + '```clojure\n' + originalString + '\n```'
);
if (level === null) {
this.contextValue = 'raw';
} else if (level === 0) {
Expand Down

0 comments on commit 28663c0

Please sign in to comment.