Skip to content

Commit 08c1a0b

Browse files
author
Yaroslav Lepenkin
committed
Fixed slow-mo on check not null in presentation.
1 parent 3776c21 commit 08c1a0b

4 files changed

Lines changed: 64 additions & 94 deletions

File tree

META-INF/plugin.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
<actionRecognizer implementation="com.jetbrains.idear.actions.recognition.RunActionRecognizer"/>
5151
<actionRecognizer implementation="com.jetbrains.idear.actions.recognition.DebugActionRecognizer"/>
5252
<actionRecognizer implementation="com.jetbrains.idear.actions.recognition.FindUsagesActionRecognizer"/>
53-
<actionRecognizer implementation="com.jetbrains.idear.actions.recognition.NavigateToDeclarationRecognizer"/>
5453
<actionRecognizer implementation="com.jetbrains.idear.actions.recognition.RenameActionRecognizer"/>
5554
<actionRecognizer implementation="com.jetbrains.idear.actions.recognition.SurroundWithNoNullCheckRecognizer"/>
5655
</extensions>

src/com/jetbrains/idear/GoogleHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class GoogleHelper {
2424

2525
private static Logger logger = Logger.getLogger(GoogleHelper.class.getSimpleName());
2626

27-
private static final String API_KEY = "AIzaSyB0DS1X9_qkZw2keZWw9p9EwUb9cV2bYsw";
27+
// private static final String API_KEY = "AIzaSyB0DS1X9_qkZw2keZWw9p9EwUb9cV2bYsw";
2828
private static final String URL_PRE = "https://www.google.com/speech-api/v2/recognize";
2929
private static final String URL_SEARCH = "https://www.google.com/search?q=";
3030

31-
private static final String ONE_MORE_API_KEY = "AIzaSyDhaglUIfPFvtYqKKpmhLQfkeiBBzgT2XE";
31+
private static final String API_KEY = "AIzaSyDhaglUIfPFvtYqKKpmhLQfkeiBBzgT2XE";
3232

3333
private static List<Pair<String, Double>> getRecognizedTextForUtteranceInternal(File utterance) {
3434
try {

src/com/jetbrains/idear/asr/ASRServiceImpl.java

Lines changed: 61 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.intellij.ide.DataManager;
44
import com.intellij.openapi.actionSystem.*;
55
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
6+
import com.intellij.openapi.application.ApplicationManager;
67
import com.intellij.openapi.components.ServiceManager;
78
import com.intellij.openapi.util.Pair;
89
import com.intellij.util.Consumer;
@@ -143,6 +144,7 @@ private class ASRControlLoop implements Runnable {
143144
public static final String HI_IDEA = "hi idea";
144145
public static final String WHERE_AM_I = "where am i";
145146
public static final String NAVIGATE = "navigate";
147+
public static final String EXECUTE = "execute";
146148

147149

148150
@Override
@@ -180,49 +182,35 @@ private void applyAction(String c) {
180182
if (c.equals(HI_IDEA)) {
181183
// Greet some more
182184
say("Hi, again!");
183-
}
184-
185-
else if (c.equals(FUCK)) {
185+
} else if (c.equals(FUCK)) {
186186
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_Z);
187187
//invokeAction(IdeActions.ACTION_UNDO);
188-
}
189-
190-
else if (c.startsWith(OPEN)) {
188+
} else if (c.startsWith(OPEN)) {
191189
if (c.endsWith(SETTINGS)) {
192190
invokeAction(IdeActions.ACTION_SHOW_SETTINGS);
193191
} else if (c.endsWith(RECENT)) {
194192
invokeAction(IdeActions.ACTION_RECENT_FILES);
195193
} else if (c.endsWith(TERMINAL)) {
196194
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_F12);
197195
}
198-
}
199-
200-
else if (c.startsWith(NAVIGATE)) {
196+
} else if (c.startsWith(NAVIGATE)) {
201197
invokeAction("GotoDeclaration");
202-
}
203-
204-
else if (c.equals(WHERE_AM_I)) {
205-
// TODO(kudinkin): extract to action
198+
} else if (c.startsWith(EXECUTE)) {
199+
invokeAction("Run");
200+
} else if (c.equals(WHERE_AM_I)) {
201+
// TODO(kudinkin): extract to action
206202
invokeAction("Idear.WhereAmI");
207-
}
208-
209-
else if (c.startsWith("focus")) {
203+
} else if (c.startsWith("focus")) {
210204
if (c.endsWith("editor")) {
211205
pressKeystroke(KeyEvent.VK_ESCAPE);
212206
} else if (c.endsWith("project")) {
213207
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_1);
214208
}
215-
}
216-
217-
else if (c.startsWith("expand")) {
209+
} else if (c.startsWith("expand")) {
218210
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_W);
219-
}
220-
221-
else if (c.startsWith("shrink")) {
211+
} else if (c.startsWith("shrink")) {
222212
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_SHIFT, KeyEvent.VK_W);
223-
}
224-
225-
else if (c.startsWith("press")) {
213+
} else if (c.startsWith("press")) {
226214
if (c.contains("delete")) {
227215
pressKeystroke(KeyEvent.VK_DELETE);
228216
} else if (c.contains("return")) {
@@ -234,80 +222,62 @@ else if (c.startsWith("press")) {
234222
} else if (c.contains("undo")) {
235223
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_Z);
236224
}
237-
}
238-
239-
else if (c.startsWith("following")) {
225+
} else if (c.startsWith("following")) {
240226
if (c.endsWith("line")) {
241227
pressKeystroke(KeyEvent.VK_DOWN);
242228
} else if (c.endsWith("page")) {
243229
pressKeystroke(KeyEvent.VK_PAGE_DOWN);
244230
} else if (c.endsWith("method")) {
245231
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_DOWN);
246232
}
247-
}
248-
249-
else if (c.startsWith("previous")) {
233+
} else if (c.startsWith("previous")) {
250234
if (c.endsWith("line")) {
251235
pressKeystroke(KeyEvent.VK_UP);
252236
} else if (c.endsWith("page")) {
253237
pressKeystroke(KeyEvent.VK_PAGE_UP);
254238
} else if (c.endsWith("method")) {
255239
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_UP);
256240
}
257-
}
258-
259-
else if (c.startsWith("extract this")) {
241+
} else if (c.startsWith("extract this")) {
260242
if (c.endsWith("method")) {
261243
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_M);
262244
} else if (c.endsWith("parameter")) {
263245
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_P);
264246
}
265-
}
266-
267-
else if (c.startsWith("inspect code")) {
247+
} else if (c.startsWith("inspect code")) {
268248
pressKeystroke(KeyEvent.VK_ALT, KeyEvent.VK_SHIFT, KeyEvent.VK_I);
269-
}
270-
271-
else if (c.startsWith("speech pause")) {
249+
} else if (c.startsWith("speech pause")) {
272250
pauseSpeech();
273-
}
274-
275-
else if (c.startsWith(OK_IDEA) || c.startsWith(OKAY_IDEA)) {
251+
} else if (c.startsWith(OK_IDEA) || c.startsWith(OKAY_IDEA)) {
276252
beep();
277253
fireVoiceCommand();
278-
}
279-
280-
else if (c.startsWith(OKAY_GOOGLE) || c.startsWith(OK_GOOGLE)) {
254+
} else if (c.startsWith(OKAY_GOOGLE) || c.startsWith(OK_GOOGLE)) {
281255
beep();
282256
fireGoogleSearch();
283-
}
284-
285-
else if(c.contains("break point")) {
257+
} else if (c.contains("break point")) {
286258
if (c.startsWith("toggle")) {
287259
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_F8);
288-
} else if(c.startsWith("view")) {
260+
} else if (c.startsWith("view")) {
289261
pressKeystroke(KeyEvent.VK_CONTROL, KeyEvent.VK_SHIFT, KeyEvent.VK_F8);
290262
}
291-
}
292-
293-
else if (c.startsWith("step")) {
263+
} else if (c.startsWith("step")) {
294264
if (c.endsWith("over")) {
295265
pressKeystroke(KeyEvent.VK_F8);
296266
} else if (c.endsWith("into")) {
297267
pressKeystroke(KeyEvent.VK_F7);
298268
}
299-
}
300-
301-
else if (c.startsWith("tell me a joke")) {
269+
} else if (c.startsWith("tell me a joke")) {
302270
tellJoke();
303-
}
304-
305-
else if (c.contains("check")) {
271+
} else if (c.contains("check")) {
306272
SurroundWithNoNullCheckRecognizer r = new SurroundWithNoNullCheckRecognizer();
307273
if (r.isMatching(c)) {
308-
DataManager.getInstance().getDataContextFromFocus().doWhenDone((Consumer<DataContext>) dataContext -> {
309-
r.getActionInfo(c, dataContext);
310-
});
274+
DataManager.getInstance()
275+
.getDataContextFromFocus()
276+
.doWhenDone((Consumer<DataContext>) dataContext -> ApplicationManager
277+
.getApplication()
278+
.runWriteAction(() -> {
279+
r.getActionInfo(c, dataContext);
280+
}));
311281
}
312282
}
313283
}
@@ -359,15 +329,15 @@ private void fireVoiceCommand() {
359329
beep();
360330

361331
invokeAction(
362-
"Idear.VoiceAction",
363-
dataContext -> new AnActionEvent(
364-
null,
365-
SimpleDataContext.getSimpleContext(ExecuteVoiceCommandAction.KEY.getName(), commandTuple.first, dataContext),
366-
ActionPlaces.UNKNOWN,
367-
new Presentation(),
368-
ActionManager.getInstance(),
369-
0
370-
)
332+
"Idear.VoiceAction",
333+
dataContext -> new AnActionEvent(
334+
null,
335+
SimpleDataContext.getSimpleContext(ExecuteVoiceCommandAction.KEY.getName(), commandTuple.first, dataContext),
336+
ActionPlaces.UNKNOWN,
337+
new Presentation(),
338+
ActionManager.getInstance(),
339+
0
340+
)
371341
);
372342

373343
} catch (IOException e) {
@@ -387,8 +357,8 @@ private void fireGoogleSearch() {
387357
return;
388358

389359
ServiceManager
390-
.getService(TTSService.class)
391-
.say("I think you said " + searchQueryTuple.first + ", searching Google now");
360+
.getService(TTSService.class)
361+
.say("I think you said " + searchQueryTuple.first + ", searching Google now");
392362

393363
GoogleHelper.searchGoogle(searchQueryTuple.first);
394364

@@ -432,40 +402,40 @@ private void pressKeystroke(final int... keys) {
432402

433403
private void invokeAction(final String action) {
434404
invokeAction(
435-
action,
436-
dataContext ->
437-
new AnActionEvent(null,
438-
dataContext,
439-
ActionPlaces.UNKNOWN,
440-
new Presentation(),
441-
ActionManager.getInstance(),
442-
0
443-
)
405+
action,
406+
dataContext ->
407+
new AnActionEvent(null,
408+
dataContext,
409+
ActionPlaces.UNKNOWN,
410+
new Presentation(),
411+
ActionManager.getInstance(),
412+
0
413+
)
444414
);
445415
}
446416

447417
private void invokeAction(String action, Function<DataContext, AnActionEvent> actionFactory) {
448418
DataManager.getInstance().getDataContextFromFocus().doWhenDone(
449-
(Consumer<DataContext>) dataContext -> EventQueue.invokeLater(() -> {
450-
AnAction anAction = ActionManager.getInstance().getAction(action);
451-
anAction.actionPerformed(actionFactory.apply(dataContext));
452-
})
419+
(Consumer<DataContext>) dataContext -> EventQueue.invokeLater(() -> {
420+
AnAction anAction = ActionManager.getInstance().getAction(action);
421+
anAction.actionPerformed(actionFactory.apply(dataContext));
422+
})
453423
);
454424
}
455425

456426
// Helpers
457427

458428
public static synchronized void say(String something) {
459-
ServiceManager .getService(TTSService.class)
460-
.say(something);
429+
ServiceManager.getService(TTSService.class)
430+
.say(something);
461431
}
462432

463433
public static synchronized void beep() {
464434
Thread t = new Thread(() -> {
465435
try {
466436
Clip clip = AudioSystem.getClip();
467437
AudioInputStream inputStream = AudioSystem.getAudioInputStream(
468-
ASRServiceImpl.class.getResourceAsStream("/com.jetbrains.idear/sounds/beep.wav"));
438+
ASRServiceImpl.class.getResourceAsStream("/com.jetbrains.idear/sounds/beep.wav"));
469439
clip.open(inputStream);
470440
clip.start();
471441
} catch (Exception e) {
@@ -477,7 +447,8 @@ public static synchronized void beep() {
477447

478448
try {
479449
t.join();
480-
} catch (InterruptedException _) {}
450+
} catch (InterruptedException _) {
451+
}
481452
}
482453

483454
// This is for testing purposes solely

src/resources/com.jetbrains.idear/grammars/command.gram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ grammar dialog;
4444

4545
<focus_command> = focus (editor | project);
4646

47-
<run_command> = run;
47+
<run_command> = execute;
4848

4949
<speech_command> = speech <speech_action>;
5050

0 commit comments

Comments
 (0)