Skip to content

Commit 698b253

Browse files
Add command to open VFS files
1 parent b66810d commit 698b253

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ out
22
node_modules
33
.vscode-test
44
*.vsix
5+
tmp

.vscodeignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ src/node_modules/**
1616
!src/node_modules/vscode-languageserver-protocol/**
1717
!src/node_modules/vscode-languageserver-types/**
1818
!src/node_modules/{minimatch,brace-expansion,concat-map,balanced-match}/**
19-
!src/node_modules/{semver,lru-cache,yallist}/**
19+
!src/node_modules/{semver,lru-cache,yallist}/**
20+
tmp
21+
_opam

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Imandra Inc",
66
"publisher": "imandra",
77
"license": "MIT",
8-
"version": "0.0.6",
8+
"version": "0.0.7",
99
"repository": {
1010
"type": "git",
1111
"url": "https://github.com/imandra-ai/imandrax-vscode"
@@ -132,6 +132,10 @@
132132
{
133133
"command": "imandrax.clear_cache",
134134
"title": "ImandraX: Clear cache"
135+
},
136+
{
137+
"command": "imandrax.open_vfs_file",
138+
"title": "Imandrax: open VFS file"
135139
}
136140
]
137141
},

src/extension.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
env,
99
Uri,
1010
TerminalOptions,
11-
Range
11+
Range,
12+
TextDocumentContentProvider
1213
} from "vscode";
1314

1415
import {
@@ -59,6 +60,24 @@ export function activate(context: ExtensionContext) {
5960
const clear_cache_handler = () => { clear_cache(); };
6061
context.subscriptions.push(commands.registerCommand(clear_cache_cmd, clear_cache_handler));
6162

63+
const open_vfs_file_cmd = "imandrax.open_vfs_file";
64+
const open_vfs_file_handler = async () => {
65+
const what = await window.showInputBox({ placeHolder: 'file name?' });
66+
if (what) {
67+
const uri = Uri.parse(what);
68+
const doc = await workspace.openTextDocument(uri);
69+
await window.showTextDocument(doc, { preview: false });
70+
}
71+
};
72+
context.subscriptions.push(commands.registerCommand(open_vfs_file_cmd, open_vfs_file_handler));
73+
74+
const vfs_provider = new (class implements TextDocumentContentProvider {
75+
async provideTextDocumentContent(uri: Uri): Promise<string> {
76+
return await client.sendRequest<string>("$imandrax/req-vfs-file", { "uri": uri } );
77+
}
78+
})();
79+
context.subscriptions.push(workspace.registerTextDocumentContentProvider("imandrax-vfs", vfs_provider));
80+
6281
// Start language server
6382
const config = workspace.getConfiguration("imandrax");
6483
const binary = config.lsp.binary;

0 commit comments

Comments
 (0)