From 1c633b88652d3450e842b5d6200d9e49e4dab7d1 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Fri, 25 Nov 2016 16:06:17 +0100 Subject: [PATCH] PT #134848903: added syntax coloring to eclipse-lsp editors for properties and yaml files --- .../.classpath | 7 +++ .../META-INF/MANIFEST.MF | 6 +- .../plugin.xml | 24 ++++++++ ...pringPropertiesPresentationReconciler.java | 56 +++++++++++++++++++ .../SpringYMLPresentationReconciler.java | 36 ++++++++++++ 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 eclipse-extensions/org.springframework.boot.ide.properties.editors/.classpath create mode 100644 eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringPropertiesPresentationReconciler.java create mode 100644 eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringYMLPresentationReconciler.java diff --git a/eclipse-extensions/org.springframework.boot.ide.properties.editors/.classpath b/eclipse-extensions/org.springframework.boot.ide.properties.editors/.classpath new file mode 100644 index 000000000..eca7bdba8 --- /dev/null +++ b/eclipse-extensions/org.springframework.boot.ide.properties.editors/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/eclipse-extensions/org.springframework.boot.ide.properties.editors/META-INF/MANIFEST.MF b/eclipse-extensions/org.springframework.boot.ide.properties.editors/META-INF/MANIFEST.MF index bc52abefd..a72582697 100644 --- a/eclipse-extensions/org.springframework.boot.ide.properties.editors/META-INF/MANIFEST.MF +++ b/eclipse-extensions/org.springframework.boot.ide.properties.editors/META-INF/MANIFEST.MF @@ -7,4 +7,8 @@ Bundle-Vendor: Pivotal, Inc. Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Require-Bundle: org.eclipse.languageserver;bundle-version="0.1.0", org.eclipse.ui.genericeditor;bundle-version="1.0.0", - org.eclipse.core.runtime;bundle-version="3.12.0" + org.eclipse.core.runtime;bundle-version="3.12.0", + org.eclipse.jface.text;bundle-version="3.11.100", + org.eclipse.jdt.ui;bundle-version="3.13.0", + org.dadacoalition.yedit;bundle-version="1.0.20" +Import-Package: org.eclipse.jface.preference diff --git a/eclipse-extensions/org.springframework.boot.ide.properties.editors/plugin.xml b/eclipse-extensions/org.springframework.boot.ide.properties.editors/plugin.xml index 3b2ef82ff..bec3136c7 100644 --- a/eclipse-extensions/org.springframework.boot.ide.properties.editors/plugin.xml +++ b/eclipse-extensions/org.springframework.boot.ide.properties.editors/plugin.xml @@ -71,4 +71,28 @@ + + + + + + + + + + + + + + + diff --git a/eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringPropertiesPresentationReconciler.java b/eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringPropertiesPresentationReconciler.java new file mode 100644 index 000000000..4f74da2c4 --- /dev/null +++ b/eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringPropertiesPresentationReconciler.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2016 Pivotal, Inc. + * 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: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.boot.ide.properties.editors; + +import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions; +import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertyValueScanner; +import org.eclipse.jdt.internal.ui.text.SingleTokenJavaScanner; +import org.eclipse.jdt.ui.PreferenceConstants; +import org.eclipse.jdt.ui.text.IColorManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.ITokenScanner; + +/** + * @author Martin Lippert + */ +@SuppressWarnings("restriction") +public class SpringPropertiesPresentationReconciler extends PresentationReconciler { + + public SpringPropertiesPresentationReconciler() { + + IColorManager colorManager = JavaPlugin.getDefault().getJavaTextTools().getColorManager(); + IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore(); + + ITokenScanner propertyKeyScanner= new SingleTokenJavaScanner(colorManager, store, PreferenceConstants.PROPERTIES_FILE_COLORING_KEY); + ITokenScanner propertyValueScanner= new PropertyValueScanner(colorManager, store); + ITokenScanner propertyCommentScanner= new SingleTokenJavaScanner(colorManager, store, PreferenceConstants.PROPERTIES_FILE_COLORING_COMMENT); + + this.setDocumentPartitioning(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING); + + DefaultDamagerRepairer dr= new DefaultDamagerRepairer(propertyKeyScanner); + this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + + dr= new DefaultDamagerRepairer(propertyCommentScanner); + this.setDamager(dr, IPropertiesFilePartitions.COMMENT); + this.setRepairer(dr, IPropertiesFilePartitions.COMMENT); + + dr= new DefaultDamagerRepairer(propertyValueScanner); + this.setDamager(dr, IPropertiesFilePartitions.PROPERTY_VALUE); + this.setRepairer(dr, IPropertiesFilePartitions.PROPERTY_VALUE); + + } + +} diff --git a/eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringYMLPresentationReconciler.java b/eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringYMLPresentationReconciler.java new file mode 100644 index 000000000..c4d8729f0 --- /dev/null +++ b/eclipse-extensions/org.springframework.boot.ide.properties.editors/src/org/springframework/boot/ide/properties/editors/SpringYMLPresentationReconciler.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2016 Pivotal, Inc. + * 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: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.boot.ide.properties.editors; + +import org.dadacoalition.yedit.editor.ColorManager; +import org.dadacoalition.yedit.editor.YEditDamageRepairer; +import org.dadacoalition.yedit.editor.scanner.YAMLScanner; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.presentation.PresentationReconciler; +import org.eclipse.jface.text.rules.DefaultDamagerRepairer; +import org.eclipse.jface.text.rules.ITokenScanner; + +/** + * @author Martin Lippert + */ +public class SpringYMLPresentationReconciler extends PresentationReconciler { + + public SpringYMLPresentationReconciler() { + + ColorManager colorManager = new ColorManager(); + ITokenScanner yamlScanner = new YAMLScanner( colorManager ); + DefaultDamagerRepairer dr = new YEditDamageRepairer(yamlScanner); + + this.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + this.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + } + +}