[lsapi] added default coloring, throw exception when no languages are registered.

This commit is contained in:
Sven Efftinge 2016-06-01 15:22:32 +02:00
parent 900e930fb3
commit 58bea403a8
3 changed files with 64 additions and 3 deletions

View file

@ -32,4 +32,5 @@ Export-Package: org.eclipse.xtext.ide;x-friends:="org.eclipse.xtend.ide",
org.eclipse.xtext.ide.server.concurrent,
org.eclipse.xtext.ide.server.contentassist,
org.eclipse.xtext.ide.server.findReferences,
org.eclipse.xtext.ide.server.symbol
org.eclipse.xtext.ide.server.symbol,
org.eclipse.xtext.ide.util

View file

@ -7,10 +7,67 @@
*******************************************************************************/
package org.eclipse.xtext.ide.editor.syntaxcoloring
import com.google.inject.ImplementedBy
import com.google.inject.Inject
import org.eclipse.xtext.GrammarUtil
import org.eclipse.xtext.IGrammarAccess
import org.eclipse.xtext.LanguageInfo
/**
* @author Sven Efftinge - Initial contribution and API
*/
@ImplementedBy(DefaultImpl)
interface IEditorHighlightingConfigurationProvider {
/**
* provides an editor specific highlighting configuration or null.
*/
def String getConfiguration(String editorName)
}
static class DefaultImpl implements IEditorHighlightingConfigurationProvider {
@Inject IGrammarAccess grammarAccess
@Inject LanguageInfo languageInfo
override getConfiguration(String editorName) {
if (editorName == 'EclipseChe' || editorName == 'EclipseOrion') {
return '''
[
«getStandardPatterns»
{
match: "\\\\b(?:«keywords.join('|')»)\\\\b",
name: "keyword.«languageInfo.shortName»"
}
]
'''
} else {
return '''
'''
}
}
def getGetStandardPatterns() '''
{include: "orion.c-like#comment_singleLine"},
{include: "orion.c-like#comment_block"},
{include: "orion.lib#string_doubleQuote"},
{include: "orion.lib#string_singleQuote"},
{include: "orion.lib#number_decimal"},
{include: "orion.lib#number_hex"},
{include: "orion.lib#brace_open"},
{include: "orion.lib#brace_close"},
{include: "orion.lib#bracket_open"},
{include: "orion.lib#bracket_close"},
{include: "orion.lib#parenthesis_open"},
{include: "orion.lib#parenthesis_close"},
{include: "orion.lib#operator"},
{include: "orion.lib#doc_block"},
'''
def Iterable<String> getKeywords() {
GrammarUtil.containedKeywords(grammarAccess.grammar).filter [
Character.isJavaIdentifierStart(it.value.charAt(0))
].map[value].toSet.sort
}
}
}

View file

@ -94,6 +94,9 @@ import static io.typefox.lsapi.util.LsapiFactories.*
if (params.rootPath === null) {
throw new IllegalArgumentException("Bad initialization request. rootPath must not be null.")
}
if (languagesRegistry.extensionToFactoryMap.isEmpty) {
throw new IllegalStateException("No Xtext languages have been registered. Please make sure you have added the languages's setup class in '/META-INF/services/org.eclipse.xtext.ISetup'")
}
this.params = params
workspaceManager = workspaceManagerProvider.get
resourceAccess = new WorkspaceResourceAccess(workspaceManager)