From 58bea403a895712263d4ad07fcaaf9de8eb4d010 Mon Sep 17 00:00:00 2001 From: Sven Efftinge Date: Wed, 1 Jun 2016 15:22:32 +0200 Subject: [PATCH] [lsapi] added default coloring, throw exception when no languages are registered. --- .../META-INF/MANIFEST.MF | 3 +- ...torHighlightingConfigurationProvider.xtend | 61 ++++++++++++++++++- .../xtext/ide/server/LanguageServerImpl.xtend | 3 + 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF index 4300d899f..526860b8c 100644 --- a/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF @@ -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 diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/IEditorHighlightingConfigurationProvider.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/IEditorHighlightingConfigurationProvider.xtend index d8541e170..7d8ff8bd4 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/IEditorHighlightingConfigurationProvider.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/editor/syntaxcoloring/IEditorHighlightingConfigurationProvider.xtend @@ -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) -} \ No newline at end of file + + 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 getKeywords() { + GrammarUtil.containedKeywords(grammarAccess.grammar).filter [ + Character.isJavaIdentifierStart(it.value.charAt(0)) + ].map[value].toSet.sort + } + + } +} diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend index 94c33ad8f..50787ab57 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend @@ -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)