@@ -3,6 +3,41 @@ import * as vscode from 'vscode';
33import { Uri } from "vscode" ;
44
55export 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+
641 // Extract the file name in a cross-platform way
742 const fileName = path . basename ( uri . fsPath , '.dart' ) ;
843 if ( ! fileName ) {
@@ -326,7 +361,7 @@ export const sealedStates = async (uri: Uri) => {
326361 codeBuilder . push ( '' ) ;
327362
328363 // Insert the generated code into the current document
329- const editor = vscode . window . activeTextEditor ;
364+ // const editor = vscode.window.activeTextEditor;
330365 if ( editor ) {
331366 editor . insertSnippet ( new vscode . SnippetString ( codeBuilder . join ( '\n' ) ) ) ;
332367 /* editor.edit(editBuilder => {
0 commit comments