Skip to content

Commit 55a821d

Browse files
committed
Update to 0.4.1
- Added command `orca_toc: Toggle Collapse/Expand All TOC Entries` to toggle collapse/expand all TOC entries at once. The collapsed status of the TOC view will be preserved when navigating between different ORCA output files. The default collapsed status of the TOC view can be changed in the settings of the extension. - Update of the `patterns.json` file for better parsing of the ORCA output file.
1 parent 0319905 commit 55a821d

File tree

5 files changed

+80
-35
lines changed

5 files changed

+80
-35
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
6464
- Added cursor position tracking for the ORCA output file. The TOC view will automatically highlight and expand the corresponding TOC entry when the user is navigating through the ORCA output file based on the current line number. The highlight and expand status of the TOC view will be updated when the user is moving the cursor to a different line in the ORCA output file.
6565
- Added support for changing the highlight symbols for the TOC entries.
6666
- Added support for saving the collapsed status of the TOC view in the settings of the extension. When navigating to different ORCA output files, the TOC view status for each file will be restored.
67+
68+
## [0.4.1] - 2023-12-30
69+
70+
- Added command `orca_toc: Toggle Collapse/Expand All TOC Entries` to toggle collapse/expand all TOC entries at once. The collapsed status of the TOC view will be preserved when navigating between different ORCA output files. The default collapsed status of the TOC view can be changed in the settings of the extension.
71+
- Update of the `patterns.json` file for better parsing of the ORCA output file.

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ By default all the parent entries are collapsed. While navigating through the OR
1919

2020
The collapsed status of the TOC view could also be changed by clicking the toggle arrow next to each parent entry. The manually changed collapsed status of the TOC view for each ORCA output file will be preserved when navigating between different ORCA output files.
2121

22+
Settings of this extension can be changed in the settings of VS Code (click on the gear icon in the bottom left corner of the VS Code window or press `Ctrl+,` on Windows or `Cmd+,` on Mac). The configuration options are listed under `Extensions` -> `ORCA_TOC`, or could be accessed by searching `ORCA_TOC` in the search bar of the settings window.
23+
2224
![Outline Example](images/outline_example.png)
2325

2426
![Outline Example Expanded](images/outline_example_expanded.png)
2527

26-
The TOC view can also be triggered manually by running the command `Show ORCA Outline` from the command palette. On Windows, the command palette can be opened with `Ctrl+Shift+P`, on Mac it is `Cmd+Shift+P`. The TOC view is automatically updated when navigating to a different ORCA output file, or when an ORCA output file is opened.
28+
The TOC view can also be triggered manually by running the command `orca_toc: Show ORCA Outline` from the command palette. On Windows, the command palette can be opened with `Ctrl+Shift+P`, on Mac it is `Cmd+Shift+P`. The TOC view is automatically updated when navigating to a different ORCA output file, or when an ORCA output file is opened.
2729

2830
![Command Palette Example](images/command_palette_example.png)
2931

@@ -48,7 +50,7 @@ For a list of available highlight symbols, please see [here](https://code.visual
4850

4951
- If you have very large ORCA output files, please first consider splitting them into smaller chunks or remove the parts that are not needed (for example full print of the MOs).
5052

51-
- :warning: For large ORCA output files, The current solution is using the `FileSystemProvider` API to read the contents of the ORCA output file directly from the file system. This will allow the extension to parse ORCA output files that are larger than 50MB. please use the command `Show ORCA Outline External` from the command palette and load the large ORCA output file manually from your file system. The loaded ORCA output file will be displayed in a new tab in the editor of the current VS Code window, with a :lock: symbol at the end of the file name. This is because the file is read-only and cannot be modified. The TOC view will be automatically populated with the contents of this ORCA output file.
53+
- :warning: For large ORCA output files, The current solution is using the `FileSystemProvider` API to read the contents of the ORCA output file directly from the file system. This will allow the extension to parse ORCA output files that are larger than 50MB. please use the command `orca_toc: Show ORCA Outline External` from the command palette and load the large ORCA output file manually from your file system. The loaded ORCA output file will be displayed in a new tab in the editor of the current VS Code window, with a :lock: symbol at the end of the file name. This is because the file is read-only and cannot be modified. The TOC view will be automatically populated with the contents of this ORCA output file.
5254

5355
- :construction: A known issue is that clicking the heading titles in the `ORCA FILE OUTLINE` view for large ORCA output files will not navigate to the corresponding line in the opened tab. Instead a new tab with the same name file name will pop up, showing identical contents and TOC view at the respective line. This bug will be fixed in a future release.
5456

@@ -60,11 +62,10 @@ For a list of available highlight symbols, please see [here](https://code.visual
6062

6163
For detailed release notes, please see [CHANGELOG.md](CHANGELOG.md).
6264

63-
### 0.4.0
65+
### 0.4.1
6466

65-
- Added cursor position tracking for the ORCA output file. The TOC view will automatically highlight and expand the corresponding TOC entry when the user is navigating through the ORCA output file based on the current line number. The highlight and expand status of the TOC view will be updated when the user is moving the cursor to a different line in the ORCA output file.
66-
- Added support for changing the highlight symbols for the TOC entries.
67-
- Added support for saving the collapsed status of the TOC view in the settings of the extension. When navigating to different ORCA output files, the TOC view status for each file will be restored.
67+
- Added command `orca_toc: Toggle Collapse/Expand All TOC Entries` to toggle collapse/expand all TOC entries at once. The collapsed status of the TOC view will be preserved when navigating between different ORCA output files. The default collapsed status of the TOC view can be changed in the settings of the extension.
68+
- Update of the `patterns.json` file for better parsing of the ORCA output file.
6869

6970
## TODO
7071

@@ -73,15 +74,12 @@ For detailed release notes, please see [CHANGELOG.md](CHANGELOG.md).
7374
- [x] Add support for the `ORCA FILE OUTLINE` view to automatically scroll to the current line in the ORCA output file.
7475
- [x] Syntax highliting for the ORCA output file based on the TOC entries.
7576
- [x] Add settings for enabling/disabling the syntax highlighting for the ORCA output file.
76-
- [ ] Add command for unfold/fold all TOC entries
77+
- [x] Add command for toggle collapse/expand the TOC view.
7778
- [x] Add option to choose different highlight symbols for the TOC entries
7879
- [ ] Update illustration figures in this README
79-
80-
## Roadmap
81-
82-
The current version represents an early release of this extension.
83-
84-
An important feature that will be added in the next major release is to enable the scrolling of the `ORCA FILE OUTLINE` view to the current line in the ORCA output file. This will be useful when the ORCA output file is very long and the user is navigating through the file. The `ORCA FILE OUTLINE` view will automatically scroll to the current line in the ORCA output file.
80+
- [ ] Update the `orca.tmLanguage.json` file to include more syntax definitions for the ORCA output file
81+
- [ ] Update the `patterns.json` file to include more regular expressions for parsing the ORCA output file
82+
- [ ] Update the `keywords.json` file to include more keywords for replacing the matched text
8583

8684
## For Developers
8785

extension.js

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,29 @@ class OrcaOutlineProvider {
5151
// console.log('treeItem.iconPath: ', treeItem.iconPath);
5252
// console.log('element.children: ', element.children);
5353

54-
// Check if the element has children and set the collapsible state accordingly based on the highlighted state, isExpanded state, or the default collapsed state
55-
if (element.children && element.children.length > 0) {
56-
// Check if an expanded state has been set, otherwise use the default, or set to expanded if highlighted
57-
const isExpanded = this._expandedState[element.label || element.title];
54+
// Check the expanded state for the element saved in the global expanded state object
55+
const isExpanded = this._expandedState[element.label || element.title]; // Get the expanded state from the expanded state object
5856

59-
if (isExpanded !== undefined) {
60-
// If there is an expanded state, use it, or set to expanded if highlighted
61-
treeItem.collapsibleState = element.highlighted ? vscode.TreeItemCollapsibleState.Expanded : isExpanded ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed
57+
// Check if the element has children and set the collapsible state accordingly
58+
if (element.children && element.children.length > 0) {
59+
if (element.highlighted) {
60+
// If highlighted, set to expanded
61+
treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
6262
} else {
63-
// If there is no expanded state, use the default collapsed state, or set to expanded if highlighted
64-
treeItem.collapsibleState = element.highlighted ? vscode.TreeItemCollapsibleState.Expanded : defaultCollapsed ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.Expanded;
63+
if (element.collapsed !== undefined) {
64+
// If the collapsed state is set, use it
65+
treeItem.collapsibleState = element.collapsed ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.Expanded;
66+
this._expandedState[element.label || element.title] = !element.collapsed; // Save the expanded state in the expanded state object
67+
} else {
68+
if (isExpanded !== undefined) {
69+
// If the expanded state is set, use it
70+
treeItem.collapsibleState = isExpanded ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed;
71+
}
72+
else {
73+
// If neither the collapsed state nor the expanded state is set, use the default collapsed state
74+
treeItem.collapsibleState = defaultCollapsed ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.Expanded;
75+
}
76+
}
6577
}
6678
} else {
6779
// If there are no children, set the collapsible state to none
@@ -77,7 +89,7 @@ class OrcaOutlineProvider {
7789

7890
// Create a unique id for each treeItem using the file path and the label and the level and the collapsed state
7991
// by creating a unique id will force the tree view to refresh when the collapsed state changes
80-
treeItem.id = `${this._filePath}::${treeItem.label}::${element.level}::${treeItem.collapsibleState}::${element.highlighted}`;
92+
treeItem.id = `${this._filePath}::${treeItem.label}::${element.level}::${treeItem.collapsibleState}::${element.highlighted}::${element.collapsed}`;
8193
return treeItem;
8294
}
8395

@@ -145,7 +157,7 @@ class OrcaOutlineProvider {
145157

146158
// Method to refresh the tree view
147159
refresh() {
148-
this._onDidChangeTreeData.fire(undefined);
160+
this._onDidChangeTreeData.fire(undefined); // Trigger the event emitter
149161
}
150162

151163
// share the matches
@@ -317,8 +329,8 @@ function parseOrcaFile(document, filePath) {
317329
title: 'Open File'
318330
},
319331
tooltip: `${pattern.title} (Line ${line + 1})`, // This will be the tooltip for the tree item
320-
highlighted: false, // This will be the highlighted state for the tree item
321-
collapsed: defaultCollapsed // This will be the collapsed state for the tree item based on the default collapsed state configuration
332+
highlighted: false, // This will be the default highlighted state for the tree item
333+
collapsed: undefined // This will be the default collapsed state for the tree item
322334
});
323335
}
324336

@@ -367,7 +379,7 @@ function insertDummyHeadings(allMatches) {
367379
command: null,
368380
tooltip: `Dummy for missing level`,
369381
highlighted: false,
370-
collapsed: defaultCollapsed
382+
collapsed: undefined
371383
});
372384
}
373385
}
@@ -409,7 +421,7 @@ function resetAllHighlights(matches) {
409421
// Iterate through the matches and reset the highlighted property
410422
matches.forEach(match => {
411423
match.highlighted = false;
412-
match.collapsed = defaultCollapsed; // Reset the collapsed state to the default
424+
// match.collapsed = undefined;
413425
// Recursively reset the highlighted property for the children
414426
if (match.children) {
415427
resetAllHighlights(match.children);
@@ -427,7 +439,7 @@ function updateTOCHighlight(lineNumber) {
427439
let matchForLevel = findClosestMatchForLevel(currentLevelMatches, lineNumber); // Find the closest match for the current level
428440
if (matchForLevel) {
429441
matchForLevel.highlighted = true; // Highlight the entry
430-
matchForLevel.collapsed = false; // Expand the entry
442+
// matchForLevel.collapsed = false; // Expand the entry
431443
currentLevelMatches = matchForLevel.children || []; // Set the current level matches to the children of the match
432444
} else {
433445
break; // Exit if no match is found at the current level
@@ -477,6 +489,27 @@ async function showOrcaOutlineExternal(context, uri) {
477489
}
478490
}
479491

492+
// Function to reset all collapse states to a specific state
493+
function resetAllCollapseStates(matches, collapsedState) {
494+
// console.log('resetAllCollapseStates');
495+
matches.forEach(match => {
496+
match.collapsed = collapsedState;
497+
// Recursively reset the collapsed state for the children
498+
if (match.children) {
499+
resetAllCollapseStates(match.children, collapsedState);
500+
}
501+
});
502+
}
503+
504+
let isAllCollapsed = defaultCollapsed; // Initialize the collapse/expand state of all TOC entries as a global variable
505+
506+
// Function to toggle the collapse/expand state of all TOC entries
507+
function toggleCollapseExpandAll() {
508+
isAllCollapsed = !isAllCollapsed; // Toggle the collapse/expand state
509+
resetAllCollapseStates(orcaOutlineProvider.getParsedMatches(), isAllCollapsed); // Reset all collapse states
510+
orcaOutlineProvider.refresh(); // Refresh the TOC view
511+
}
512+
480513
// Function to activate the extension
481514
function activate(context) {
482515
// Register the custom file system provider
@@ -511,10 +544,15 @@ function activate(context) {
511544
// listen to changes in the configuration
512545
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(e => {
513546
if (e.affectsConfiguration('orcatoc.defaultCollapsed')) {
514-
orcaOutlineProvider.refresh();
547+
console.log('orcatoc.defaultCollapsed changed');
548+
resetAllCollapseStates(orcaOutlineProvider.getParsedMatches(), undefined); // Reset all collapse states to undefined
549+
orcaOutlineProvider.refresh(); // Refresh the TOC view
515550
}
516551
}));
517552

553+
// Register the command to collapse/expand all TOC entries
554+
context.subscriptions.push(vscode.commands.registerCommand('extension.toggleCollapseExpandAll', toggleCollapseExpandAll));
555+
518556
// Highlight the TOC entry corresponding to the current cursor position
519557
context.subscriptions.push(vscode.window.onDidChangeTextEditorSelection(event => {
520558
if (event.textEditor.document.languageId === 'orcaOut' && event.textEditor.document.fileName.endsWith('.out')) {

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "orcatoc",
33
"displayName": "orca_toc",
44
"description": "Provides an outline for ORCA files in the VS Code sidebar.",
5-
"version": "0.4.0",
5+
"version": "0.4.1",
66
"engines": {
77
"vscode": "^1.82.0"
88
},
@@ -17,11 +17,15 @@
1717
"commands": [
1818
{
1919
"command": "extension.showOrcaOutline",
20-
"title": "Show ORCA Outline"
20+
"title": "orca_toc: Show ORCA Outline"
2121
},
2222
{
2323
"command": "extension.showOrcaOutlineExternal",
24-
"title": "Show ORCA Outline External"
24+
"title": "orca_toc: Show ORCA Outline External"
25+
},
26+
{
27+
"command": "extension.toggleCollapseExpandAll",
28+
"title": "orca_toc: Toggle Collapse/Expand All TOC Entries"
2529
}
2630
],
2731
"views": {
@@ -46,7 +50,7 @@
4650
}
4751
],
4852
"configuration": {
49-
"title": "ORCA Table of Contents",
53+
"title": "ORCA_TOC",
5054
"properties": {
5155
"orcatoc.defaultCollapsed": {
5256
"type": "boolean",

patterns.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"level": 2
99
},
1010
{
11-
"regex": "^\\-+\\r?\\n +([^\\r?\\n]+)\\r?\\n\\-+",
11+
"regex": "^\\-+\\r?\\n +([^\\r?\\n\\[]+)\\r?\\n\\-+",
1212
"level": 2
1313
},
1414
{

0 commit comments

Comments
 (0)