Skip to content

Commit 02238b2

Browse files
committed
feat(commands): add attach command closes #31
1 parent 0512537 commit 02238b2

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

src/commands/dev/index.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,35 @@ export class Dev extends Dispose {
112112

113113
constructor() {
114114
super();
115-
const cmdId = `${cmdPrefix}.run`;
116-
this.push(commands.registerCommand(cmdId, this.execute, this));
117-
this.push(
118-
(function() {
119-
commands.titles.set(cmdId, 'Run flutter server');
120-
return {
121-
dispose() {
122-
commands.titles.delete(cmdId);
123-
},
124-
};
125-
})(),
126-
);
115+
['run', 'attach'].forEach(cmd => {
116+
const cmdId = `${cmdPrefix}.${cmd}`;
117+
this.push(commands.registerCommand(cmdId, this[`${cmd}Server`], this));
118+
this.push(
119+
(function() {
120+
commands.titles.set(cmdId, `${cmd} flutter server`);
121+
return {
122+
dispose() {
123+
commands.titles.delete(cmdId);
124+
},
125+
};
126+
})(),
127+
);
128+
});
127129
this.push(devServer);
128130
log('register dev command');
129131
}
130132

131-
private async execute(...args: string[]) {
132-
log(`run dev server, devServer state: ${devServer.state}`);
133-
const state = await devServer.start(args);
133+
runServer(...args: string[]) {
134+
this.execute('run', args);
135+
}
136+
137+
attachServer(...args: string[]) {
138+
this.execute('attach', args);
139+
}
140+
141+
private async execute(cmd: string, args: string[]) {
142+
log(`${cmd} dev server, devServer state: ${devServer.state}`);
143+
const state = await devServer.start([cmd].concat(args));
134144
if (state) {
135145
devServer.onError(this.onError);
136146
devServer.onExit(this.onExit);
@@ -206,15 +216,15 @@ export class Dev extends Dispose {
206216
!line.startsWith('Initializing hot reload') &&
207217
!line.startsWith('Performing hot reload') &&
208218
!line.startsWith('Reloaded ') &&
209-
!line.startsWith("Flutter run key commands.") &&
210-
!line.startsWith("r Hot reload. 🔥🔥🔥") &&
211-
!line.startsWith("R Hot restart.") &&
212-
!line.startsWith("h Repeat this help message.") &&
213-
!line.startsWith("d Detach (terminate \"flutter run\" but leave application running).") &&
214-
!line.startsWith("c Clear the screen") &&
215-
!line.startsWith("q Quit (terminate the application on the device).") &&
216-
!line.startsWith("flutter: Another exception was thrown:") &&
217-
!line.startsWith("An Observatory debugger and profiler on") &&
219+
!line.startsWith('Flutter run key commands.') &&
220+
!line.startsWith('r Hot reload. 🔥🔥🔥') &&
221+
!line.startsWith('R Hot restart.') &&
222+
!line.startsWith('h Repeat this help message.') &&
223+
!line.startsWith('d Detach (terminate "flutter run" but leave application running).') &&
224+
!line.startsWith('c Clear the screen') &&
225+
!line.startsWith('q Quit (terminate the application on the device).') &&
226+
!line.startsWith('flutter: Another exception was thrown:') &&
227+
!line.startsWith('An Observatory debugger and profiler on') &&
218228
!/^flutter: #\d+ +.+$/.test(line)
219229
);
220230
});

src/server/dev/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class DevServer extends Dispose {
7979
this.outputChannel = logger.devOutchannel;
8080
}
8181

82-
this.task = spawn('flutter', ['run'].concat(args), {
82+
this.task = spawn('flutter', args, {
8383
cwd: workspaceFolder,
8484
detached: false,
8585
shell: os.platform() === 'win32' ? true : undefined,

0 commit comments

Comments
 (0)