summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Aubry2012-07-17 12:43:12 (EDT)
committersbernard2012-07-17 13:08:27 (EDT)
commit1da722c87f7f09cb56fb64b58dea41d10039e506 (patch)
tree66846669095b73b86de0b8111c8e2064c18fa316
parentde0923f19ca7878b80fd6d67c3e3cb00cb714e5f (diff)
downloadorg.eclipse.koneki.ldt-1da722c87f7f09cb56fb64b58dea41d10039e506.zip
org.eclipse.koneki.ldt-1da722c87f7f09cb56fb64b58dea41d10039e506.tar.gz
org.eclipse.koneki.ldt-1da722c87f7f09cb56fb64b58dea41d10039e506.tar.bz2
Fix auto-completion on lua doc first line
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaDocumentorCompletionProposalComputer.java96
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/ILuaPartitions.java3
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaPartitionScanner.java3
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java5
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaTextTools.java2
-rw-r--r--plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/folding/LuaCommentFoldingBlockProvider.java1
6 files changed, 82 insertions, 28 deletions
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaDocumentorCompletionProposalComputer.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaDocumentorCompletionProposalComputer.java
index 5ff7879..2ef8ea7 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaDocumentorCompletionProposalComputer.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/completion/LuaDocumentorCompletionProposalComputer.java
@@ -15,6 +15,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.dltk.compiler.CharOperation;
@@ -27,11 +29,14 @@ import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.koneki.ldt.ui.internal.Activator;
import org.eclipse.koneki.ldt.ui.internal.editor.LuaDocumentorTags;
import org.eclipse.koneki.ldt.ui.internal.editor.templates.LuaDocumentorTemplateCompletionProcessor;
+import org.eclipse.koneki.ldt.ui.internal.editor.text.ILuaPartitions;
public class LuaDocumentorCompletionProposalComputer implements IScriptCompletionProposalComputer {
@@ -47,44 +52,85 @@ public class LuaDocumentorCompletionProposalComputer implements IScriptCompletio
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
IDocument document = context.getDocument();
try {
- final IRegion region = document.getLineInformationOfOffset(context.getInvocationOffset());
- final char[] line = document.get(region.getOffset(), region.getLength()).toCharArray();
- final int offsetInLine = context.getInvocationOffset() - region.getOffset();
- int index = 0;
- index = skipSpaces(line, index, offsetInLine);
- if (index < offsetInLine && line[index] == '-') {
- ++index;
- }
- if (index < offsetInLine && line[index] == '-') {
- ++index;
+
+ final IRegion contentAssistRegion = document.getLineInformationOfOffset(context.getInvocationOffset());
+ final char[] contentAssistLine = document.get(contentAssistRegion.getOffset(), contentAssistRegion.getLength()).toCharArray();
+ final int contentAssistOffsetInLine = context.getInvocationOffset() - contentAssistRegion.getOffset();
+
+ int offsetInCurrentLine = 0;
+
+ // Check if we are on the first line of the lua doc bloc to known how many hyphens we have to ignore
+ ITypedRegion[] partitions = TextUtilities.computePartitioning(document, ILuaPartitions.LUA_PARTITIONING, 0, document.getLength(), false);
+ for (ITypedRegion region : partitions) {
+ if (ILuaPartitions.LUA_DOC.equals(region.getType()) || ILuaPartitions.LUA_DOC_MULTI.equals(region.getType())) {
+ if (context.getInvocationOffset() >= region.getOffset()
+ && context.getInvocationOffset() < (region.getOffset() + region.getLength())) {
+ // "region" is the current region
+ int blockFirstLine = document.getLineOfOffset(region.getOffset());
+ int invocationLine = document.getLineOfOffset(context.getInvocationOffset());
+ boolean isInvocationOnFirstLine = (blockFirstLine == invocationLine);
+
+ if (isInvocationOnFirstLine) {
+ offsetInCurrentLine = region.getOffset() - document.getLineOffset(blockFirstLine);
+ } else {
+ offsetInCurrentLine = 0;
+ }
+
+ if (ILuaPartitions.LUA_DOC_MULTI.equals(region.getType())) {
+ if (isInvocationOnFirstLine) {
+ offsetInCurrentLine = skipOpenningMultiLineChars(contentAssistLine, offsetInCurrentLine, contentAssistOffsetInLine);
+ }
+ } else if (ILuaPartitions.LUA_DOC.equals(region.getType())) {
+ if (isInvocationOnFirstLine) {
+ offsetInCurrentLine += 3;
+ } else {
+ offsetInCurrentLine += 2;
+ }
+ }
+ }
+ }
}
- index = skipSpaces(line, index, offsetInLine);
- if (!(index < offsetInLine && line[index] == '@')) {
+
+ offsetInCurrentLine = skipSpaces(contentAssistLine, offsetInCurrentLine, contentAssistOffsetInLine);
+
+ if (!(offsetInCurrentLine < contentAssistOffsetInLine && contentAssistLine[offsetInCurrentLine] == '@')) {
return Collections.emptyList();
}
- final int tagStart = index;
- ++index;
- if (index < offsetInLine && Character.isJavaIdentifierStart(line[index])) {
- ++index;
- while (index < offsetInLine && (Character.isJavaIdentifierPart(line[index]) || line[index] == '.' || line[index] == '-')) {
- ++index;
+
+ final int tagStart = offsetInCurrentLine;
+ ++offsetInCurrentLine;
+ if (offsetInCurrentLine < contentAssistOffsetInLine && Character.isJavaIdentifierStart(contentAssistLine[offsetInCurrentLine])) {
+ ++offsetInCurrentLine;
+ while (offsetInCurrentLine < contentAssistOffsetInLine
+ && (Character.isJavaIdentifierPart(contentAssistLine[offsetInCurrentLine]) || contentAssistLine[offsetInCurrentLine] == '.' || contentAssistLine[offsetInCurrentLine] == '-')) {
+ ++offsetInCurrentLine;
}
}
- if (index == offsetInLine) {
- return completionOnTag(context, new String(line, tagStart, index - tagStart));
+
+ if (offsetInCurrentLine == contentAssistOffsetInLine) {
+ return completionOnTag(context, new String(contentAssistLine, tagStart, offsetInCurrentLine - tagStart));
}
+
} catch (BadLocationException e) {
Activator.logError("Compute completion proposal error", e); //$NON-NLS-1$
}
return Collections.emptyList();
}
- private static int skipSpaces(final char[] line, int index, int offsetInLine) {
- int i = index;
- while (i < offsetInLine && Character.isWhitespace(line[index])) {
- i++;
+ private static int skipOpenningMultiLineChars(char[] contentAssistLine, int offsetInCurrentLine, int contentAssistOffsetInLine) {
+ Pattern pattern = Pattern.compile("--\\[=*\\[-");//$NON-NLS-1$
+ Matcher matcher = pattern.matcher(new String(contentAssistLine));
+ if (matcher.find()) {
+ return matcher.end();
+ }
+ return offsetInCurrentLine;
+ }
+
+ private static int skipSpaces(final char[] line, int offsetInCurrentLine, int offsetInLine) {
+ while (offsetInCurrentLine < offsetInLine && Character.isWhitespace(line[offsetInCurrentLine])) {
+ offsetInCurrentLine++;
}
- return index;
+ return offsetInCurrentLine;
}
private List<ICompletionProposal> completionOnTag(ContentAssistInvocationContext context, String tag) {
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/ILuaPartitions.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/ILuaPartitions.java
index f305271..faf4581 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/ILuaPartitions.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/ILuaPartitions.java
@@ -22,8 +22,9 @@ public interface ILuaPartitions {
public static final String LUA_SINGLE_QUOTE_STRING = "__lua_single_quote_string"; //$NON-NLS-1$
public static final String LUA_MULTI_LINE_STRING = "__lua_multi_line_string"; //$NON-NLS-1$
public static final String LUA_DOC = "__lua_doc"; //$NON-NLS-1$
+ public static final String LUA_DOC_MULTI = "__lua_doc_multi_line"; //$NON-NLS-1$
static final String[] LUA_PARTITION_TYPES = new String[] { IDocument.DEFAULT_CONTENT_TYPE, ILuaPartitions.LUA_COMMENT,
ILuaPartitions.LUA_COMMENT, ILuaPartitions.LUA_STRING, ILuaPartitions.LUA_SINGLE_QUOTE_STRING, ILuaPartitions.LUA_MULTI_LINE_STRING,
- ILuaPartitions.LUA_MULTI_LINE_COMMENT, ILuaPartitions.LUA_DOC, ILuaPartitions.LUA_NUMBER };
+ ILuaPartitions.LUA_MULTI_LINE_COMMENT, ILuaPartitions.LUA_DOC, ILuaPartitions.LUA_DOC_MULTI, ILuaPartitions.LUA_NUMBER };
}
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaPartitionScanner.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaPartitionScanner.java
index 0f7e9a5..7e2e97f 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaPartitionScanner.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaPartitionScanner.java
@@ -48,11 +48,12 @@ public class LuaPartitionScanner extends RuleBasedPartitionScanner {
*/
IToken doc = new Token(ILuaPartitions.LUA_DOC);
+ IToken docMultiLine = new Token(ILuaPartitions.LUA_DOC_MULTI);
IToken multiLineComment = new Token(ILuaPartitions.LUA_MULTI_LINE_COMMENT);
IToken singleLineComment = new Token(ILuaPartitions.LUA_COMMENT);
// Multi-line documentation
- rules.add(new MultiLineStringOrCommentRule(multiLineComment, doc));
+ rules.add(new MultiLineStringOrCommentRule(multiLineComment, docMultiLine));
// Documentation starting with "---"
rules.add(new LuaDocSingleCommentSeriesRule(doc));
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java
index b141398..cc51eea 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaSourceViewerConfiguration.java
@@ -63,6 +63,7 @@ public class LuaSourceViewerConfiguration extends ScriptSourceViewerConfiguratio
ContentAssistProcessor luaDocumentorProcessor = new LuaCompletionProcessor(getEditor(), assistant, ILuaPartitions.LUA_DOC);
assistant.setContentAssistProcessor(luaDocumentorProcessor, ILuaPartitions.LUA_DOC);
+ assistant.setContentAssistProcessor(luaDocumentorProcessor, ILuaPartitions.LUA_DOC_MULTI);
}
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
@@ -111,6 +112,10 @@ public class LuaSourceViewerConfiguration extends ScriptSourceViewerConfiguratio
reconciler.setDamager(dr, ILuaPartitions.LUA_DOC);
reconciler.setRepairer(dr, ILuaPartitions.LUA_DOC);
+ dr = new DefaultDamagerRepairer(fDocScanner);
+ reconciler.setDamager(dr, ILuaPartitions.LUA_DOC_MULTI);
+ reconciler.setRepairer(dr, ILuaPartitions.LUA_DOC_MULTI);
+
return reconciler;
}
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaTextTools.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaTextTools.java
index a312666..013e7cc 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaTextTools.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/LuaTextTools.java
@@ -22,7 +22,7 @@ public class LuaTextTools extends ScriptTextTools {
private static final String[] LEGAL_CONTENT_TYPES = new String[] { ILuaPartitions.LUA_STRING, ILuaPartitions.LUA_COMMENT,
ILuaPartitions.LUA_SINGLE_QUOTE_STRING, ILuaPartitions.LUA_MULTI_LINE_STRING, ILuaPartitions.LUA_MULTI_LINE_COMMENT,
- ILuaPartitions.LUA_DOC, ILuaPartitions.LUA_NUMBER };
+ ILuaPartitions.LUA_DOC, ILuaPartitions.LUA_DOC_MULTI, ILuaPartitions.LUA_NUMBER };
public LuaTextTools(boolean autoDisposeOnDisplayDispose) {
super(ILuaPartitions.LUA_PARTITIONING, LEGAL_CONTENT_TYPES, autoDisposeOnDisplayDispose);
diff --git a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/folding/LuaCommentFoldingBlockProvider.java b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/folding/LuaCommentFoldingBlockProvider.java
index 385e648..46ca2f9 100644
--- a/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/folding/LuaCommentFoldingBlockProvider.java
+++ b/plugins/org.eclipse.koneki.ldt.ui/src/org/eclipse/koneki/ldt/ui/internal/editor/text/folding/LuaCommentFoldingBlockProvider.java
@@ -28,6 +28,7 @@ public class LuaCommentFoldingBlockProvider extends PartitioningFoldingBlockProv
}
if (isFoldingDocs()) {
computeBlocksForPartitionType(content, ILuaPartitions.LUA_DOC, LuaFoldingBlockKind.DOC, isCollapseDocs());
+ computeBlocksForPartitionType(content, ILuaPartitions.LUA_DOC_MULTI, LuaFoldingBlockKind.DOC, isCollapseDocs());
}
}
}