Skip to content

Commit b19ca96

Browse files
committed
Update to version 0.2.3
1 parent 3056072 commit b19ca96

File tree

4 files changed

+100
-94
lines changed

4 files changed

+100
-94
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
3737
- removed debug lines from extension.js
3838
- update of keywords.json
3939
- update of patterns.json. Now the extension could handle both CRLF and LF line breaks in the regular expressions.
40+
41+
## [0.2.3] - 2023-10-17
42+
43+
- Bug fixes and optimizations
44+
- Update of `patterns.json` file
45+
- Added support for large ORCA output files (>50MB).Added a new command `Show ORCA Outline External` to allow the user to load large ORCA output files manually from the file system.
46+
- Fixed a bug by adding dummy headings to the `ORCA FILE OUTLINE` view when the heading levels are not in strict ascending order.

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,51 @@ This an extension for Visual Studio Code that provides a separate toggleable TOC
44

55
## Features
66

7-
This extension provides a separate toggleable TOC view in the sidebar. The TOC view is automatically populated with the contents of the ORCA output file that is currently open in the editor. The TOC view is generated by parsing the ORCA output file using regular expressions and setting up a tree view based on the results. The generated TOC view is a tree view with the titles of the headings in the ORCA output file and the corresponding line numbers. Clicking on a TOC entry will jump to the corresponding line in the ORCA output file. The TOC view can be toggled on and off by clicking on the `ORCA FILE OUTLINE` icon in the sidebar. The TOC view can also be toggled on 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.
7+
This extension provides a separate toggleable TOC view in the sidebar. The TOC view is automatically populated with the contents of the ORCA output file that is currently open in the editor. The TOC view is generated by parsing the ORCA output file using regular expressions and setting up a tree view based on the results. The generated TOC view is a tree view with the titles of the headings in the ORCA output file and the corresponding line numbers. Clicking on a TOC entry will jump to the corresponding line in the ORCA output file.
8+
9+
The TOC view can be toggled on and off by clicking on the `ORCA FILE OUTLINE` icon in the sidebar. The TOC view can also be toggled on 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.
810

911
## Requirements
1012

1113
N/A
1214

1315
## Extension Settings
1416

15-
The current version (0.2.2) of this extension does not have any settings.
17+
The current version (0.2.3) of this extension does not have any settings.
1618

1719
## Issues and Important Notes
1820

19-
- Due to the memory limit of VS Code for large files, the extension will not work properly for very large ORCA output files (>50MB) because VS code will disable the `activeEditor`. To parse very large ORCA output files and generate the TOC view, the extension will need to be run in a separate process. This will be implemented in a future release. Currently, the extension will work for ORCA output files that are less than 50MB in size. If you have very large ORCA output files, please consider splitting them into smaller chunks or remove the parts that are not needed (for example full print of the MOs).
21+
- Due to the memory limit of VS Code for large files, could not process files larger than 50MB automatically. This is because the VS Code restricts the size of the `activeEditor` to 50MB, which prevents the extension from getting the contents of the opened ORCA output file.
22+
23+
- 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).
24+
25+
- :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.
26+
27+
- :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.
28+
29+
- :warning: **(Not Recommended!)** Another solution for large ORCA output files is by patching the `workbench.desktop.main.js` file to increase the limit. The default value of `_MODEL_SYNC_LIMIT` is `50 * 1024 * 1024`, which is 50MB. You could change it to a value that is larger than the size of your ORCA output file. This will cause VS Code to display a warining message that the installation is corrupted. Please use this solution at your own risk.
2030

2131
- If you don's see the `ORCA FILE OUTLINE` in the sidebar of `EXPLORER`, please make sure that the `OPEN EDITORS` drop down menu is expanded. This is a known issue and will be fixed in a future release.
2232

2333
## Release Notes
2434

2535
For detailed release notes, please see [CHANGELOG.md](CHANGELOG.md).
2636

27-
### 0.2.2
37+
### 0.2.3
2838

2939
Bug fixes and optimizations.
3040

3141
## TODO
3242

3343
- [x] Automatically show TOC view when opening an ORCA output file
34-
- [X] Support for large ORCA output files (<50MB).
35-
- [ ] Automatically update TOC view when saving changes to an ORCA output file (additional command to manually refresh TOC view)
36-
- [ ] Add support for enabling/disabling TOC view for specific file types
37-
- [ ] Add support for controlling the showing level of TOC entries
44+
- [X] Support for large ORCA output files (>50MB).
3845
- [ ] Add illustrations to this README
3946
- [x] Add icon to this extension
4047
- [x] Updating the list of regular expressions used to parse the ORCA output file
4148

4249
## Roadmap
4350

44-
The current version represents a very early release of this extension.
51+
The current version represents an early release of this extension.
4552

4653
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.
4754

@@ -54,6 +61,8 @@ The list of regular expressions is saved in `patterns.json` file. The file conta
5461

5562
Please submit a pull request if you would like to add a new regular expression to the list. Please also submit a pull request if you would like to modify an existing regular expression.
5663

64+
A list of keywords that are used to format the headings in the TOC view is saved in `keywords.json` file. The matched strings will be formatted using the corresponding keywords. This list is currently not complete and will be updated in a future release.
65+
5766
## For more information
5867

5968
[ORCA forum](https://orcaforum.kofo.mpg.de/)

extension.js

Lines changed: 74 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,80 @@ class OrcaOutlineProvider {
8181
}
8282
}
8383

84+
85+
class OrcaFileSystemProvider {
86+
constructor() {
87+
this._emitter = new vscode.EventEmitter();
88+
this.onDidChangeFile = this._emitter.event;
89+
}
90+
async readFile(uri) {
91+
try {
92+
const fsPath = uri.fsPath;
93+
const fileStream = fs.createReadStream(fsPath, { encoding: 'utf8', highWaterMark: 1024 * 1024 }); // 1MB chunks
94+
let buffer = '';
95+
for await (const chunk of fileStream) {
96+
buffer += chunk;
97+
// Skip lines as per your requirement
98+
buffer = buffer.replace(/^(\ {0,3}\d+.*\n)/gm, '\n');
99+
// Process buffer with regex here...
100+
}
101+
return Buffer.from(buffer);
102+
} catch (error) {
103+
console.error(`Failed to read file: ${error.message}`);
104+
throw new Error(`Failed to read file: ${error.message}`);
105+
}
106+
}
107+
watch(uri, options) {
108+
const watcher = fs.watch(uri.fsPath, (event, filename) => {
109+
if (event === 'change') {
110+
this._emitter.fire([{ type: vscode.FileChangeType.Changed, uri }]);
111+
}
112+
});
113+
114+
return { dispose: () => watcher.close() };
115+
}
116+
stat(uri) {
117+
try {
118+
const stats = fs.statSync(uri.fsPath);
119+
const type = stats.isFile() ? vscode.FileType.File : stats.isDirectory() ? vscode.FileType.Directory : vscode.FileType.Unknown;
120+
return { type, ctime: stats.ctimeMs, mtime: stats.mtimeMs, size: stats.size };
121+
} catch (error) {
122+
throw vscode.FileSystemError.FileNotFound(uri);
123+
}
124+
}
125+
/**
126+
* @param {vscode.Uri} uri
127+
* @return {[string, vscode.FileType][]}
128+
*/
129+
readDirectory(uri) {
130+
try {
131+
const entries = fs.readdirSync(uri.fsPath, { withFileTypes: true });
132+
return entries.map(entry => {
133+
const type = entry.isFile() ? vscode.FileType.File :
134+
entry.isDirectory() ? vscode.FileType.Directory :
135+
vscode.FileType.Unknown;
136+
return [entry.name, type];
137+
});
138+
} catch (error) {
139+
throw vscode.FileSystemError.FileNotFound(uri);
140+
}
141+
}
142+
143+
createDirectory(uri) {
144+
throw vscode.FileSystemError.NoPermissions('Creating directories is not allowed.');
145+
}
146+
writeFile(uri, content, options) {
147+
throw vscode.FileSystemError.NoPermissions('Writing to files is not allowed.');
148+
}
149+
delete(uri, options) {
150+
throw vscode.FileSystemError.NoPermissions('Deleting files is not allowed.');
151+
}
152+
rename(oldUri, newUri, options) {
153+
throw vscode.FileSystemError.NoPermissions('Renaming files is not allowed.');
154+
}
155+
}
156+
157+
84158
let orcaOutlineProvider = new OrcaOutlineProvider([]);
85159

86160
async function showOrcaOutline() { // Make the function asynchronous
@@ -249,92 +323,8 @@ function activate(context) {
249323
showOrcaOutline();
250324
}
251325
}));
252-
// Initial check if the currently opened document meets the conditions
253-
const activeEditor = vscode.window.activeTextEditor;
254-
if (activeEditor && activeEditor.document.languageId === 'orcaOut' && activeEditor.document.fileName.endsWith('.out')) {
255-
showOrcaOutline();
256-
}
257-
context.subscriptions.push(vscode.commands.registerCommand('extension.navigateToLine', (lineNumber) => {
258-
if (globalEditor) {
259-
let position = new vscode.Position(lineNumber, 0);
260-
let range = new vscode.Range(position, position);
261-
globalEditor.selection = new vscode.Selection(position, position);
262-
globalEditor.revealRange(range, vscode.TextEditorRevealType.Default);
263-
}
264-
}));
265-
266-
267-
}
268-
269-
270-
class OrcaFileSystemProvider {
271-
constructor() {
272-
this._emitter = new vscode.EventEmitter();
273-
this.onDidChangeFile = this._emitter.event;
274-
}
275-
async readFile(uri) {
276-
try {
277-
const fsPath = uri.fsPath;
278-
const fileStream = fs.createReadStream(fsPath, { encoding: 'utf8', highWaterMark: 1024 * 1024 }); // 1MB chunks
279-
let buffer = '';
280-
for await (const chunk of fileStream) {
281-
buffer += chunk;
282-
// Skip lines as per your requirement
283-
buffer = buffer.replace(/^(\ {0,3}\d+.*\n)/gm, '\n');
284-
// Process buffer with regex here...
285-
}
286-
return Buffer.from(buffer);
287-
} catch (error) {
288-
console.error(`Failed to read file: ${error.message}`);
289-
throw new Error(`Failed to read file: ${error.message}`);
290-
}
291-
}
292-
watch(uri, options) {
293-
const watcher = fs.watch(uri.fsPath, (event, filename) => {
294-
if (event === 'change') {
295-
this._emitter.fire([{ type: vscode.FileChangeType.Changed, uri }]);
296-
}
297-
});
298-
299-
return { dispose: () => watcher.close() };
300-
}
301-
stat(uri) {
302-
try {
303-
const stats = fs.statSync(uri.fsPath);
304-
const type = stats.isFile() ? vscode.FileType.File : stats.isDirectory() ? vscode.FileType.Directory : vscode.FileType.Unknown;
305-
return { type, ctime: stats.ctimeMs, mtime: stats.mtimeMs, size: stats.size };
306-
} catch (error) {
307-
throw vscode.FileSystemError.FileNotFound(uri);
308-
}
309-
}
310-
readDirectory(uri) {
311-
try {
312-
const entries = fs.readdirSync(uri.fsPath, { withFileTypes: true });
313-
return entries.map(entry => {
314-
const type = entry.isFile() ? vscode.FileType.File :
315-
entry.isDirectory() ? vscode.FileType.Directory :
316-
vscode.FileType.Unknown;
317-
return [entry.name, type];
318-
});
319-
} catch (error) {
320-
throw vscode.FileSystemError.FileNotFound(uri);
321-
}
322-
}
323-
createDirectory(uri) {
324-
throw vscode.FileSystemError.NoPermissions('Creating directories is not allowed.');
325-
}
326-
writeFile(uri, content, options) {
327-
throw vscode.FileSystemError.NoPermissions('Writing to files is not allowed.');
328-
}
329-
delete(uri, options) {
330-
throw vscode.FileSystemError.NoPermissions('Deleting files is not allowed.');
331-
}
332-
rename(oldUri, newUri, options) {
333-
throw vscode.FileSystemError.NoPermissions('Renaming files is not allowed.');
334-
}
335326
}
336327

337-
338328
async function showOrcaOutlineExternal(context, uri) {
339329

340330
// Prompt the user to select a .out file

package.json

Lines changed: 1 addition & 1 deletion
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.2.2",
5+
"version": "0.2.3",
66
"engines": {
77
"vscode": "^1.82.0"
88
},

0 commit comments

Comments
 (0)