Skip to content

Commit f31cc86

Browse files
authored
Merge pull request #139 from Krzmbrzl/plugin
Finished work on 0.7.2 release
2 parents 0db786e + 0294734 commit f31cc86

File tree

166 files changed

+6933
-5852
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+6933
-5852
lines changed

plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: Editors
44
Bundle-SymbolicName: raven.sqdev.editors;singleton:=true
5-
Bundle-Version: 0.6.2
5+
Bundle-Version: 0.6.3
66
Bundle-Activator: raven.sqdev.editors.activator.Activator
77
Require-Bundle: org.eclipse.ui,
88
org.eclipse.core.runtime,
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicCodeEditor.java

+123-57
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import org.eclipse.core.runtime.IStatus;
1313
import org.eclipse.core.runtime.Status;
1414
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
15-
import org.eclipse.core.runtime.jobs.IJobChangeListener;
1615
import org.eclipse.core.runtime.jobs.Job;
16+
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
1717
import org.eclipse.jface.preference.IPreferenceStore;
1818
import org.eclipse.jface.text.BadLocationException;
1919
import org.eclipse.jface.text.IDocument;
@@ -101,8 +101,14 @@ public class BasicCodeEditor extends TextEditor {
101101
* A list of character pairs that should be used in this editor
102102
*/
103103
protected List<CharacterPair> characterPairs;
104-
104+
/**
105+
* The <code>Job</code> used to parse if no suspension is wished
106+
*/
105107
private Job parseJob;
108+
/**
109+
* Indicates whether the current parsing should be cancelled
110+
*/
111+
private Boolean parsingIsCancelled;
106112

107113
public BasicCodeEditor() {
108114
super();
@@ -115,6 +121,7 @@ public BasicCodeEditor() {
115121

116122
managerList = new ArrayList<IManager>();
117123
characterPairs = getCharacterPairs();
124+
parsingIsCancelled = false;
118125

119126
// add a implementation for the autoCompletion of pairing characters
120127
configureCharacterPairHandler();
@@ -150,12 +157,12 @@ public ISourceViewer createSourceViewer(Composite parent,
150157
getEditorKeyEventQueue().setManager(manager);
151158

152159
((ITextViewerExtension) viewer).appendVerifyKeyListener(manager);
153-
154-
// add listener that parses the input during typing
155-
((ITextViewerExtension) viewer)
156-
.appendVerifyKeyListener(new BasicParseTimeListener(this));
157160
}
158161

162+
// add parse listener
163+
getBasicProvider().getDocument(getEditorInput())
164+
.addDocumentListener(new BasicParseTimeListener(this));
165+
159166
return viewer;
160167
}
161168

@@ -278,7 +285,7 @@ public void createPartControl(Composite parent) {
278285
createManagers(managerList);
279286

280287
// parse the input for the first time
281-
parseInput();
288+
parseInput(true);
282289
}
283290

284291
/**
@@ -292,6 +299,8 @@ public void createPartControl(Composite parent) {
292299
* Whether it is necessary to reconfigure the sourceVieweer
293300
*/
294301
public void update(boolean reconfigureSourceViewer) {
302+
// TODO: gets called way to often on editor opening
303+
295304
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
296305

297306
@Override
@@ -357,17 +366,70 @@ public List<String> getParseRuleNames() {
357366
return parseRuleNames;
358367
}
359368

369+
/**
370+
* This is a helper method that will do the parsing for the given input
371+
* wihtout any checks (whetehr there is an active parsing job) and in the
372+
* same thread as it is called
373+
*
374+
* @param input
375+
* The input to parse
376+
* @return The result of the parsing in form of an IStatus
377+
*/
378+
private IStatus startParsingInput(String input) {
379+
// preprocess
380+
doPreprocessorParsing(input);
381+
382+
// check if this parsing should be cancelled
383+
synchronized (parsingIsCancelled) {
384+
if (parsingIsCancelled) {
385+
parsingIsCancelled = false;
386+
return Status.CANCEL_STATUS;
387+
}
388+
}
389+
390+
// parse
391+
ParseTree output = doParse(input);
392+
393+
// check if this parsing should be cancelled
394+
synchronized (parsingIsCancelled) {
395+
if (parsingIsCancelled) {
396+
parsingIsCancelled = false;
397+
return Status.CANCEL_STATUS;
398+
}
399+
}
400+
401+
if (output == null || output.getChildCount() == 0) {
402+
applyParseChanges();
403+
404+
return Status.CANCEL_STATUS;
405+
} else {
406+
parseTree = output;
407+
408+
if (!processParseTree(parseTree)) {
409+
applyParseChanges();
410+
}
411+
412+
return Status.OK_STATUS;
413+
}
414+
}
415+
360416
/**
361417
* Parses the input of this editor, updates the parseTree and sends it to
362418
* the {@link #processParseTree(ParseTree)} method automatically. Before
363419
* doing so it will call the preprocessor parser via
364420
* {@link #doPreprocessorParsing(String)}. If you need to specify a custom
365421
* preprocessor parser or disable it you have to overwrite that method.
366422
*
423+
* @param suspend
424+
* Indicates whether the calling thread should be suspended until
425+
* the parsing is done. If there is currently another
426+
* {@link #parseJob} the parsing will be rescheduled but the
427+
* suspension will be cancelled
428+
*
367429
* @return <code>True</code> if the parsing could be done successfully and
368430
* <code>False</code> otherwise
369431
*/
370-
public boolean parseInput() {
432+
public boolean parseInput(boolean suspend) {
371433
if (getEditorInput() == null) {
372434
return false;
373435
}
@@ -384,74 +446,78 @@ public boolean parseInput() {
384446
return false;
385447
}
386448

449+
synchronized (parsingIsCancelled) {
450+
if (parsingIsCancelled
451+
&& (parseJob == null || parseJob.getResult() != null)) {
452+
// There is no other parsing in progress that should be
453+
// cancelled and cancelling is only possible after having
454+
// initialized it
455+
parsingIsCancelled = false;
456+
}
457+
}
458+
387459
if (parseJob != null && parseJob.getState() != Job.NONE) {
388460
// Ther previous Job is still running -> reschedule
389-
parseJob.addJobChangeListener(new IJobChangeListener() {
390-
391-
@Override
392-
public void sleeping(IJobChangeEvent event) {
393-
}
394-
395-
@Override
396-
public void scheduled(IJobChangeEvent event) {
397-
}
398-
399-
@Override
400-
public void running(IJobChangeEvent event) {
401-
}
461+
parseJob.addJobChangeListener(new JobChangeAdapter() {
402462

403463
@Override
404464
public void done(IJobChangeEvent event) {
405-
// As there has been a request to parse the input again do
465+
// As there has been a request to parse the input again
466+
// do
406467
// it now as the old parsing process is finished
407468
parseInput();
408469
}
409-
410-
@Override
411-
public void awake(IJobChangeEvent event) {
412-
}
413-
414-
@Override
415-
public void aboutToRun(IJobChangeEvent event) {
416-
}
417470
});
418471

419472
return false;
420473
}
421474

422-
parseJob = new Job(
423-
"Parsing \"" + getEditorInput().getName() + "\"...") {
424-
425-
@Override
426-
protected IStatus run(IProgressMonitor monitor) {
427-
// preprocess
428-
doPreprocessorParsing(input);
429-
430-
// parse
431-
ParseTree output = doParse(input);
475+
if (suspend) {
476+
startParsingInput(input);
477+
} else {
478+
parseJob = new Job(
479+
"Parsing \"" + getEditorInput().getName() + "\"...") {
432480

433-
if (output == null) {
434-
applyParseChanges();
435-
436-
return Status.CANCEL_STATUS;
437-
} else {
438-
parseTree = output;
439-
440-
if (!processParseTree(parseTree)) {
441-
applyParseChanges();
442-
}
443-
444-
return Status.OK_STATUS;
481+
@Override
482+
protected IStatus run(IProgressMonitor monitor) {
483+
return startParsingInput(input);
445484
}
446-
}
447-
};
448-
449-
// start parsing
450-
parseJob.schedule();
485+
};
486+
487+
// schedule parsing
488+
parseJob.schedule();
489+
}
451490

452491
return true;
453492
}
454493

494+
/**
495+
* Parses the input of this editor, updates the parseTree and sends it to
496+
* the {@link #processParseTree(ParseTree)} method automatically. Before
497+
* doing so it will call the preprocessor parser via
498+
* {@link #doPreprocessorParsing(String)}. If you need to specify a custom
499+
* preprocessor parser or disable it you have to overwrite that method.<br>
500+
* This method will not wait until the parsing is done. If you need the
501+
* parsing to be done when this method returns youo can use
502+
* {@link #parseInput(boolean)} instead
503+
*
504+
* @return <code>True</code> if the parsing could be done successfully and
505+
* <code>False</code> otherwise
506+
*/
507+
public boolean parseInput() {
508+
return parseInput(false);
509+
}
510+
511+
/**
512+
* This method will cancel a running parse-process or at least the
513+
* corresponding processing of the parse result
514+
*/
515+
public void cancelParsing() {
516+
synchronized (parsingIsCancelled) {
517+
parsingIsCancelled = true;
518+
}
519+
}
520+
455521
/**
456522
* A default implementation of a preprocessor parser that parses the input
457523
* first and sets the found macros if this editor is an instance of

plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicErrorListener.java

+6
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,17 @@ public void suppressErrors(boolean suppress) {
135135
*/
136136
public void flushSuppressedErros() {
137137
synchronized (suppressedErrors) {
138+
boolean wasSuppressing = suppressErrors;
139+
suppressErrors = false;
140+
138141
for (Error currentError : suppressedErrors) {
139142
reportError(currentError);
140143
}
141144

142145
suppressedErrors.clear();
146+
147+
// recreate status from before
148+
suppressErrors = wasSuppressing;
143149
}
144150
}
145151

plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicMarkerManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public BasicMarkerManager(BasicCodeEditor editor) {
4343
this.editor = editor;
4444

4545
markers = new ArrayList<MarkerInformation>();
46+
isValid = true;
4647
}
4748

4849
/**

plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicParseTimeListener.java

+13-25
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import java.util.concurrent.TimeUnit;
77

88
import org.eclipse.core.runtime.Assert;
9-
import org.eclipse.swt.custom.VerifyKeyListener;
10-
import org.eclipse.swt.events.VerifyEvent;
9+
import org.eclipse.jface.text.DocumentEvent;
10+
import org.eclipse.jface.text.IDocumentListener;
1111

1212
import raven.sqdev.util.SQDevPreferenceUtil;
1313

@@ -18,7 +18,7 @@
1818
* @author Raven
1919
*
2020
*/
21-
public class BasicParseTimeListener implements VerifyKeyListener {
21+
public class BasicParseTimeListener implements IDocumentListener {
2222
/**
2323
* The editor this listener works on
2424
*/
@@ -52,31 +52,19 @@ public BasicParseTimeListener(BasicCodeEditor editor) {
5252
}
5353

5454
@Override
55-
public void verifyKey(VerifyEvent event) {
56-
if (runningTask != null && !runningTask.isCancelled() && !runningTask.isDone()) {
55+
public void documentChanged(DocumentEvent event) {
56+
if (runningTask != null && !runningTask.isCancelled()
57+
&& !runningTask.isDone()) {
5758
runningTask.cancel(true);
59+
editor.cancelParsing();
5860
}
5961

60-
int basicDelay = SQDevPreferenceUtil.getParseDelay();
61-
62-
switch (event.character) {
63-
case ';':
64-
// semicolon=end of statement -> parse fastly after key event
65-
runningTask = timer.schedule(parsing, basicDelay / 4, TimeUnit.MILLISECONDS);
66-
break;
67-
68-
case ' ':
69-
case '\n':
70-
case '\b':
71-
// whitespace indicates the end of a word -> parse normal after
72-
// key event
73-
runningTask = timer.schedule(parsing, basicDelay / 2, TimeUnit.MILLISECONDS);
74-
break;
75-
76-
default:
77-
// any other character -> parse slowly after key event
78-
runningTask = timer.schedule(parsing, basicDelay, TimeUnit.MILLISECONDS);
79-
}
62+
runningTask = timer.schedule(parsing,
63+
SQDevPreferenceUtil.getParseDelay(), TimeUnit.MILLISECONDS);
64+
}
65+
66+
@Override
67+
public void documentAboutToBeChanged(DocumentEvent event) {
8068
}
8169

8270
}

plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/MultiKeywordScanner.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public MultiKeywordScanner(KeywordScanner scanner, BasicCodeEditor editor) {
7272
* @param editor
7373
* The <code>BasicCodeEditor</code> this scanner works for
7474
*/
75-
public MultiKeywordScanner(Collection<KeywordScanner> scanners, BasicCodeEditor editor) {
75+
public MultiKeywordScanner(Collection<KeywordScanner> scanners,
76+
BasicCodeEditor editor) {
7677
this(editor);
7778

7879
addScanners(scanners);
@@ -214,6 +215,10 @@ public IToken evaluate(ICharacterScanner scanner) {
214215
return Token.UNDEFINED;
215216
}
216217

218+
// go on to the next char -> prevents endless loop in case c is
219+
// word start but not a word part
220+
c = (char) scanner.read();
221+
217222
while (detector.isWordPart(c)) {
218223
c = (char) scanner.read();
219224
}

0 commit comments

Comments
 (0)