mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 205984: Comment Code templates do not work
This commit is contained in:
parent
f7f62c4ee4
commit
f9d0d47ba3
4 changed files with 61 additions and 18 deletions
|
@ -1833,12 +1833,8 @@
|
|||
<completionProposalComputer
|
||||
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
|
||||
class="org.eclipse.cdt.internal.ui.text.contentassist.DOMCompletionProposalComputer">
|
||||
<partition
|
||||
type="__dftl_partition_content_type">
|
||||
</partition>
|
||||
<partition
|
||||
type="__c_preprocessor">
|
||||
</partition>
|
||||
<partition type="__dftl_partition_content_type"/>
|
||||
<partition type="__c_preprocessor"/>
|
||||
</completionProposalComputer>
|
||||
</extension>
|
||||
|
||||
|
@ -1859,12 +1855,8 @@
|
|||
<completionProposalComputer
|
||||
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
|
||||
class="org.eclipse.cdt.internal.ui.text.contentassist.KeywordCompletionProposalComputer">
|
||||
<partition
|
||||
type="__dftl_partition_content_type">
|
||||
</partition>
|
||||
<partition
|
||||
type="__c_preprocessor">
|
||||
</partition>
|
||||
<partition type="__dftl_partition_content_type"/>
|
||||
<partition type="__c_preprocessor"/>
|
||||
</completionProposalComputer>
|
||||
</extension>
|
||||
<extension
|
||||
|
@ -1873,9 +1865,7 @@
|
|||
<completionProposalComputer
|
||||
categoryId="org.eclipse.cdt.ui.parserProposalCategory"
|
||||
class="org.eclipse.cdt.internal.ui.text.contentassist.HelpCompletionProposalComputer">
|
||||
<partition
|
||||
type="__dftl_partition_content_type">
|
||||
</partition>
|
||||
<partition type="__dftl_partition_content_type"/>
|
||||
</completionProposalComputer>
|
||||
</extension>
|
||||
<!-- template proposals -->
|
||||
|
@ -1887,6 +1877,7 @@
|
|||
categoryId="org.eclipse.cdt.ui.templateProposalCategory">
|
||||
<partition type="__dftl_partition_content_type"/>
|
||||
<partition type="__c_multiline_comment"/>
|
||||
<partition type="__c_singleline_comment"/>
|
||||
</completionProposalComputer>
|
||||
</extension>
|
||||
<!-- hippie word completions -->
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.eclipse.jface.preference.IPreferenceStore;
|
|||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IDocumentExtension3;
|
||||
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||
import org.eclipse.jface.text.rules.FastPartitioner;
|
||||
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
|
||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
|
@ -203,7 +202,7 @@ public class CTextTools {
|
|||
ICPartitions.C_PREPROCESSOR
|
||||
};
|
||||
|
||||
return new FastPartitioner(getPartitionScanner(), types);
|
||||
return new FastCPartitioner(getPartitionScanner(), types);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.ITypedRegion;
|
||||
import org.eclipse.jface.text.rules.FastPartitioner;
|
||||
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
|
||||
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
|
||||
/**
|
||||
* A slightly adapted FastPartitioner.
|
||||
*/
|
||||
public class FastCPartitioner extends FastPartitioner {
|
||||
|
||||
/**
|
||||
* Creates a new partitioner for the given content types.
|
||||
*
|
||||
* @param scanner
|
||||
* @param legalContentTypes
|
||||
*/
|
||||
public FastCPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
|
||||
super(scanner, legalContentTypes);
|
||||
}
|
||||
|
||||
public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
|
||||
if (preferOpenPartitions && offset == fDocument.getLength() && offset > 0) {
|
||||
ITypedRegion region = super.getPartition(offset - 1, false);
|
||||
try {
|
||||
if (ICPartitions.C_MULTI_LINE_COMMENT.equals(region.getType())) {
|
||||
if (!fDocument.get(offset - 2, 2).equals("*/")) { //$NON-NLS-1$
|
||||
return region;
|
||||
}
|
||||
} else if (ICPartitions.C_SINGLE_LINE_COMMENT.equals(region .getType())) {
|
||||
if (fDocument.getChar(offset - 1) != '\n') {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
} catch (BadLocationException exc) {
|
||||
}
|
||||
}
|
||||
return super.getPartition(offset, preferOpenPartitions);
|
||||
}
|
||||
}
|
|
@ -75,7 +75,7 @@ public class TemplateCompletionProposalComputer implements ICompletionProposalCo
|
|||
TemplateEngine engine= null;
|
||||
try {
|
||||
String partition= TextUtilities.getContentType(viewer.getDocument(), ICPartitions.C_PARTITIONING, offset, true);
|
||||
if (partition.equals(ICPartitions.C_MULTI_LINE_COMMENT)) {
|
||||
if (partition.equals(ICPartitions.C_MULTI_LINE_COMMENT) || partition.equals(ICPartitions.C_SINGLE_LINE_COMMENT)) {
|
||||
engine= fCommentTemplateEngine;
|
||||
} else {
|
||||
if (isValidContext(context)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue