Skip to content

Commit

Permalink
Merge pull request #139 from Krzmbrzl/plugin
Browse files Browse the repository at this point in the history
Finished work on 0.7.2 release
  • Loading branch information
Krzmbrzl authored Apr 5, 2017
2 parents 0db786e + 0294734 commit f31cc86
Show file tree
Hide file tree
Showing 166 changed files with 6,933 additions and 5,852 deletions.
2 changes: 1 addition & 1 deletion plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Editors
Bundle-SymbolicName: raven.sqdev.editors;singleton:=true
Bundle-Version: 0.6.2
Bundle-Version: 0.6.3
Bundle-Activator: raven.sqdev.editors.activator.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand Down
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.
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.
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
180 changes: 123 additions & 57 deletions plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicCodeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
Expand Down Expand Up @@ -101,8 +101,14 @@ public class BasicCodeEditor extends TextEditor {
* A list of character pairs that should be used in this editor
*/
protected List<CharacterPair> characterPairs;

/**
* The <code>Job</code> used to parse if no suspension is wished
*/
private Job parseJob;
/**
* Indicates whether the current parsing should be cancelled
*/
private Boolean parsingIsCancelled;

public BasicCodeEditor() {
super();
Expand All @@ -115,6 +121,7 @@ public BasicCodeEditor() {

managerList = new ArrayList<IManager>();
characterPairs = getCharacterPairs();
parsingIsCancelled = false;

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

((ITextViewerExtension) viewer).appendVerifyKeyListener(manager);

// add listener that parses the input during typing
((ITextViewerExtension) viewer)
.appendVerifyKeyListener(new BasicParseTimeListener(this));
}

// add parse listener
getBasicProvider().getDocument(getEditorInput())
.addDocumentListener(new BasicParseTimeListener(this));

return viewer;
}

Expand Down Expand Up @@ -278,7 +285,7 @@ public void createPartControl(Composite parent) {
createManagers(managerList);

// parse the input for the first time
parseInput();
parseInput(true);
}

/**
Expand All @@ -292,6 +299,8 @@ public void createPartControl(Composite parent) {
* Whether it is necessary to reconfigure the sourceVieweer
*/
public void update(boolean reconfigureSourceViewer) {
// TODO: gets called way to often on editor opening

PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

@Override
Expand Down Expand Up @@ -357,17 +366,70 @@ public List<String> getParseRuleNames() {
return parseRuleNames;
}

/**
* This is a helper method that will do the parsing for the given input
* wihtout any checks (whetehr there is an active parsing job) and in the
* same thread as it is called
*
* @param input
* The input to parse
* @return The result of the parsing in form of an IStatus
*/
private IStatus startParsingInput(String input) {
// preprocess
doPreprocessorParsing(input);

// check if this parsing should be cancelled
synchronized (parsingIsCancelled) {
if (parsingIsCancelled) {
parsingIsCancelled = false;
return Status.CANCEL_STATUS;
}
}

// parse
ParseTree output = doParse(input);

// check if this parsing should be cancelled
synchronized (parsingIsCancelled) {
if (parsingIsCancelled) {
parsingIsCancelled = false;
return Status.CANCEL_STATUS;
}
}

if (output == null || output.getChildCount() == 0) {
applyParseChanges();

return Status.CANCEL_STATUS;
} else {
parseTree = output;

if (!processParseTree(parseTree)) {
applyParseChanges();
}

return Status.OK_STATUS;
}
}

/**
* Parses the input of this editor, updates the parseTree and sends it to
* the {@link #processParseTree(ParseTree)} method automatically. Before
* doing so it will call the preprocessor parser via
* {@link #doPreprocessorParsing(String)}. If you need to specify a custom
* preprocessor parser or disable it you have to overwrite that method.
*
* @param suspend
* Indicates whether the calling thread should be suspended until
* the parsing is done. If there is currently another
* {@link #parseJob} the parsing will be rescheduled but the
* suspension will be cancelled
*
* @return <code>True</code> if the parsing could be done successfully and
* <code>False</code> otherwise
*/
public boolean parseInput() {
public boolean parseInput(boolean suspend) {
if (getEditorInput() == null) {
return false;
}
Expand All @@ -384,74 +446,78 @@ public boolean parseInput() {
return false;
}

synchronized (parsingIsCancelled) {
if (parsingIsCancelled
&& (parseJob == null || parseJob.getResult() != null)) {
// There is no other parsing in progress that should be
// cancelled and cancelling is only possible after having
// initialized it
parsingIsCancelled = false;
}
}

if (parseJob != null && parseJob.getState() != Job.NONE) {
// Ther previous Job is still running -> reschedule
parseJob.addJobChangeListener(new IJobChangeListener() {

@Override
public void sleeping(IJobChangeEvent event) {
}

@Override
public void scheduled(IJobChangeEvent event) {
}

@Override
public void running(IJobChangeEvent event) {
}
parseJob.addJobChangeListener(new JobChangeAdapter() {

@Override
public void done(IJobChangeEvent event) {
// As there has been a request to parse the input again do
// As there has been a request to parse the input again
// do
// it now as the old parsing process is finished
parseInput();
}

@Override
public void awake(IJobChangeEvent event) {
}

@Override
public void aboutToRun(IJobChangeEvent event) {
}
});

return false;
}

parseJob = new Job(
"Parsing \"" + getEditorInput().getName() + "\"...") {

@Override
protected IStatus run(IProgressMonitor monitor) {
// preprocess
doPreprocessorParsing(input);

// parse
ParseTree output = doParse(input);
if (suspend) {
startParsingInput(input);
} else {
parseJob = new Job(
"Parsing \"" + getEditorInput().getName() + "\"...") {

if (output == null) {
applyParseChanges();

return Status.CANCEL_STATUS;
} else {
parseTree = output;

if (!processParseTree(parseTree)) {
applyParseChanges();
}

return Status.OK_STATUS;
@Override
protected IStatus run(IProgressMonitor monitor) {
return startParsingInput(input);
}
}
};

// start parsing
parseJob.schedule();
};
// schedule parsing
parseJob.schedule();
}

return true;
}

/**
* Parses the input of this editor, updates the parseTree and sends it to
* the {@link #processParseTree(ParseTree)} method automatically. Before
* doing so it will call the preprocessor parser via
* {@link #doPreprocessorParsing(String)}. If you need to specify a custom
* preprocessor parser or disable it you have to overwrite that method.<br>
* This method will not wait until the parsing is done. If you need the
* parsing to be done when this method returns youo can use
* {@link #parseInput(boolean)} instead
*
* @return <code>True</code> if the parsing could be done successfully and
* <code>False</code> otherwise
*/
public boolean parseInput() {
return parseInput(false);
}

/**
* This method will cancel a running parse-process or at least the
* corresponding processing of the parse result
*/
public void cancelParsing() {
synchronized (parsingIsCancelled) {
parsingIsCancelled = true;
}
}

/**
* A default implementation of a preprocessor parser that parses the input
* first and sets the found macros if this editor is an instance of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,17 @@ public void suppressErrors(boolean suppress) {
*/
public void flushSuppressedErros() {
synchronized (suppressedErrors) {
boolean wasSuppressing = suppressErrors;
suppressErrors = false;

for (Error currentError : suppressedErrors) {
reportError(currentError);
}

suppressedErrors.clear();

// recreate status from before
suppressErrors = wasSuppressing;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public BasicMarkerManager(BasicCodeEditor editor) {
this.editor = editor;

markers = new ArrayList<MarkerInformation>();
isValid = true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.concurrent.TimeUnit;

import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.custom.VerifyKeyListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;

import raven.sqdev.util.SQDevPreferenceUtil;

Expand All @@ -18,7 +18,7 @@
* @author Raven
*
*/
public class BasicParseTimeListener implements VerifyKeyListener {
public class BasicParseTimeListener implements IDocumentListener {
/**
* The editor this listener works on
*/
Expand Down Expand Up @@ -52,31 +52,19 @@ public BasicParseTimeListener(BasicCodeEditor editor) {
}

@Override
public void verifyKey(VerifyEvent event) {
if (runningTask != null && !runningTask.isCancelled() && !runningTask.isDone()) {
public void documentChanged(DocumentEvent event) {
if (runningTask != null && !runningTask.isCancelled()
&& !runningTask.isDone()) {
runningTask.cancel(true);
editor.cancelParsing();
}

int basicDelay = SQDevPreferenceUtil.getParseDelay();

switch (event.character) {
case ';':
// semicolon=end of statement -> parse fastly after key event
runningTask = timer.schedule(parsing, basicDelay / 4, TimeUnit.MILLISECONDS);
break;

case ' ':
case '\n':
case '\b':
// whitespace indicates the end of a word -> parse normal after
// key event
runningTask = timer.schedule(parsing, basicDelay / 2, TimeUnit.MILLISECONDS);
break;

default:
// any other character -> parse slowly after key event
runningTask = timer.schedule(parsing, basicDelay, TimeUnit.MILLISECONDS);
}
runningTask = timer.schedule(parsing,
SQDevPreferenceUtil.getParseDelay(), TimeUnit.MILLISECONDS);
}

@Override
public void documentAboutToBeChanged(DocumentEvent event) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public MultiKeywordScanner(KeywordScanner scanner, BasicCodeEditor editor) {
* @param editor
* The <code>BasicCodeEditor</code> this scanner works for
*/
public MultiKeywordScanner(Collection<KeywordScanner> scanners, BasicCodeEditor editor) {
public MultiKeywordScanner(Collection<KeywordScanner> scanners,
BasicCodeEditor editor) {
this(editor);

addScanners(scanners);
Expand Down Expand Up @@ -214,6 +215,10 @@ public IToken evaluate(ICharacterScanner scanner) {
return Token.UNDEFINED;
}

// go on to the next char -> prevents endless loop in case c is
// word start but not a word part
c = (char) scanner.read();

while (detector.isWordPart(c)) {
c = (char) scanner.read();
}
Expand Down
Loading

0 comments on commit f31cc86

Please sign in to comment.