@@ -3,6 +3,41 @@ import * as vscode from 'vscode';
3
3
import { Uri } from "vscode" ;
4
4
5
5
export const sealedStates = async ( uri : Uri ) => {
6
+ // If no URI is provided, use the active text editor
7
+ if ( ! uri ) {
8
+ const activeEditor = vscode . window . activeTextEditor ;
9
+ if ( activeEditor ) {
10
+ uri = activeEditor . document . uri ;
11
+ } else {
12
+ const selectedFiles = await vscode . window . showOpenDialog ( {
13
+ canSelectMany : false ,
14
+ openLabel : 'Select a Dart file' ,
15
+ filters : {
16
+ 'Dart Files' : [ 'dart' ]
17
+ }
18
+ } ) ;
19
+
20
+ if ( ! selectedFiles || selectedFiles . length === 0 ) {
21
+ vscode . window . showErrorMessage ( 'No file selected.' ) ;
22
+ return ;
23
+ }
24
+
25
+ uri = selectedFiles [ 0 ] ;
26
+ }
27
+ }
28
+
29
+ let document = await vscode . workspace . openTextDocument ( uri ) ;
30
+ let editor = vscode . window . activeTextEditor ;
31
+
32
+ if ( ! editor || editor . document . uri . fsPath !== uri . fsPath ) {
33
+ editor = await vscode . window . showTextDocument ( document ) ;
34
+ }
35
+
36
+ if ( ! editor ) {
37
+ vscode . window . showErrorMessage ( 'Could not open the file.' ) ;
38
+ return ;
39
+ }
40
+
6
41
// Extract the file name in a cross-platform way
7
42
const fileName = path . basename ( uri . fsPath , '.dart' ) ;
8
43
if ( ! fileName ) {
@@ -326,7 +361,7 @@ export const sealedStates = async (uri: Uri) => {
326
361
codeBuilder . push ( '' ) ;
327
362
328
363
// Insert the generated code into the current document
329
- const editor = vscode . window . activeTextEditor ;
364
+ // const editor = vscode.window.activeTextEditor;
330
365
if ( editor ) {
331
366
editor . insertSnippet ( new vscode . SnippetString ( codeBuilder . join ( '\n' ) ) ) ;
332
367
/* editor.edit(editBuilder => {
0 commit comments