From 6f9a40b2851ee57562b00d28fc2660f71d013f13 Mon Sep 17 00:00:00 2001 From: Valeriy Svydenko Date: Thu, 17 Jan 2019 11:39:53 +0200 Subject: [PATCH] [languages][java]Move java grammars from java extension to textmate-grammars Signed-off-by: Valeriy Svydenko --- .../java/src/browser/java-frontend-module.ts | 6 -- .../src/browser/monaco-contribution/index.ts | 29 ------- .../java-monaco-language.ts | 33 -------- .../java-textmate-contribution.ts | 47 ------------ .../data/java.tmLanguage.json} | 0 .../data/javadoc.tmLanguage.json} | 0 .../textmate-grammars/src/browser/java.ts | 76 +++++++++++++++++++ .../textmate-grammars-frontend-module.ts | 4 + 8 files changed, 80 insertions(+), 115 deletions(-) delete mode 100644 packages/java/src/browser/monaco-contribution/index.ts delete mode 100644 packages/java/src/browser/monaco-contribution/java-monaco-language.ts delete mode 100644 packages/java/src/browser/monaco-contribution/java-textmate-contribution.ts rename packages/{java/data/java.tmlanguage.json => textmate-grammars/data/java.tmLanguage.json} (100%) rename packages/{java/data/javadoc.tmlanguage.json => textmate-grammars/data/javadoc.tmLanguage.json} (100%) create mode 100644 packages/textmate-grammars/src/browser/java.ts diff --git a/packages/java/src/browser/java-frontend-module.ts b/packages/java/src/browser/java-frontend-module.ts index 49ca9670dccfb..533b226ba5b8d 100644 --- a/packages/java/src/browser/java-frontend-module.ts +++ b/packages/java/src/browser/java-frontend-module.ts @@ -25,12 +25,8 @@ import { JavaCommandContribution } from './java-commands'; import { JavaLabelProviderContribution } from './java-label-provider'; import { JavaResourceResolver } from './java-resource'; import { JavaEditorTextFocusContext } from './java-keybinding-contexts'; -import { JavaTextmateContribution } from './monaco-contribution/java-textmate-contribution'; -import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser/textmate/textmate-contribution'; import { bindJavaPreferences } from './java-preferences'; -import './monaco-contribution'; - export default new ContainerModule(bind => { bindJavaPreferences(bind); @@ -48,6 +44,4 @@ export default new ContainerModule(bind => { bind(ResourceResolver).toService(JavaResourceResolver); bind(LabelProviderContribution).to(JavaLabelProviderContribution).inSingletonScope(); - - bind(LanguageGrammarDefinitionContribution).to(JavaTextmateContribution).inSingletonScope(); }); diff --git a/packages/java/src/browser/monaco-contribution/index.ts b/packages/java/src/browser/monaco-contribution/index.ts deleted file mode 100644 index 7d4b4ce21cc84..0000000000000 --- a/packages/java/src/browser/monaco-contribution/index.ts +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2017 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import { JAVA_LANGUAGE_ID, JAVA_LANGUAGE_NAME } from '../../common'; -import { configuration } from './java-monaco-language'; - -monaco.languages.register({ - id: JAVA_LANGUAGE_ID, - extensions: ['.java', '.jav', '.class'], - aliases: [JAVA_LANGUAGE_NAME, 'java'], - mimetypes: ['text/x-java-source', 'text/x-java'], -}); - -monaco.languages.onLanguage(JAVA_LANGUAGE_ID, () => { - monaco.languages.setLanguageConfiguration(JAVA_LANGUAGE_ID, configuration); -}); diff --git a/packages/java/src/browser/monaco-contribution/java-monaco-language.ts b/packages/java/src/browser/monaco-contribution/java-monaco-language.ts deleted file mode 100644 index 08c78cf2df7e2..0000000000000 --- a/packages/java/src/browser/monaco-contribution/java-monaco-language.ts +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2017 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -export const configuration: monaco.languages.LanguageConfiguration = { - // the default separators except `@$` - wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g, - comments: { - lineComment: '//', - blockComment: ['/*', '*/'], - }, - brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']], - autoClosingPairs: [ - { open: '"', close: '"', notIn: ['string', 'comment'] }, - { open: '\'', close: '\'', notIn: ['string', 'comment'] }, - { open: '{', close: '}', notIn: ['string', 'comment'] }, - { open: '[', close: ']', notIn: ['string', 'comment'] }, - { open: '(', close: ')', notIn: ['string', 'comment'] }, - { open: '<', close: '>', notIn: ['string', 'comment'] }, - ] -}; diff --git a/packages/java/src/browser/monaco-contribution/java-textmate-contribution.ts b/packages/java/src/browser/monaco-contribution/java-textmate-contribution.ts deleted file mode 100644 index 9867b10f24864..0000000000000 --- a/packages/java/src/browser/monaco-contribution/java-textmate-contribution.ts +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************** - * Copyright (C) 2018 TypeFox and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the Eclipse - * Public License v. 2.0 are satisfied: GNU General Public License, version 2 - * with the GNU Classpath Exception which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - ********************************************************************************/ - -import { injectable } from 'inversify'; -import { JAVA_LANGUAGE_ID } from '../../common'; -import { LanguageGrammarDefinitionContribution, TextmateRegistry } from '@theia/monaco/lib/browser/textmate'; - -@injectable() -export class JavaTextmateContribution implements LanguageGrammarDefinitionContribution { - - registerTextmateLanguage(registry: TextmateRegistry) { - const javaDocGrammar = require('../../../data/javadoc.tmlanguage.json'); - registry.registerTextmateGrammarScope('text.html.javadoc', { - async getGrammarDefinition() { - return { - format: 'json', - content: javaDocGrammar - }; - } - }); - const scope = 'source.java'; - const javaGrammar = require('../../../data/java.tmlanguage.json'); - registry.registerTextmateGrammarScope(scope, { - async getGrammarDefinition() { - return { - format: 'json', - content: javaGrammar - }; - } - }); - - registry.mapLanguageIdToTextmateGrammar(JAVA_LANGUAGE_ID, scope); - } -} diff --git a/packages/java/data/java.tmlanguage.json b/packages/textmate-grammars/data/java.tmLanguage.json similarity index 100% rename from packages/java/data/java.tmlanguage.json rename to packages/textmate-grammars/data/java.tmLanguage.json diff --git a/packages/java/data/javadoc.tmlanguage.json b/packages/textmate-grammars/data/javadoc.tmLanguage.json similarity index 100% rename from packages/java/data/javadoc.tmlanguage.json rename to packages/textmate-grammars/data/javadoc.tmLanguage.json diff --git a/packages/textmate-grammars/src/browser/java.ts b/packages/textmate-grammars/src/browser/java.ts new file mode 100644 index 0000000000000..e9487fdfc9aef --- /dev/null +++ b/packages/textmate-grammars/src/browser/java.ts @@ -0,0 +1,76 @@ +/******************************************************************************** + * Copyright (C) 2019 Red Hat, Inc. and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ + +import { LanguageGrammarDefinitionContribution, TextmateRegistry } from '@theia/monaco/lib/browser/textmate'; +import { injectable } from 'inversify'; + +@injectable() +export class JavaContribution implements LanguageGrammarDefinitionContribution { + private readonly id = 'java'; + private readonly javaScope = 'source.java'; + private readonly javaDocScope = 'text.html.javadoc'; + + registerTextmateLanguage(registry: TextmateRegistry) { + monaco.languages.register({ + id: this.id, + extensions: [ + '.java', + '.jav', + '.class' + ], + firstLine: '(\\<\\?xml.*)|(\\\/\?\s]+)/g, + comments: { + lineComment: '//', + blockComment: ['/*', '*/'], + }, + brackets: [['{', '}'], ['[', ']'], ['(', ')'], ['<', '>']], + autoClosingPairs: [ + { open: '"', close: '"', notIn: ['string', 'comment'] }, + { open: '\'', close: '\'', notIn: ['string', 'comment'] }, + { open: '{', close: '}', notIn: ['string', 'comment'] }, + { open: '[', close: ']', notIn: ['string', 'comment'] }, + { open: '(', close: ')', notIn: ['string', 'comment'] }, + { open: '<', close: '>', notIn: ['string', 'comment'] }, + ] + }); + + const javaDocGrammar = require('../../data/java.tmLanguage.json'); + registry.registerTextmateGrammarScope(this.javaDocScope, { + async getGrammarDefinition() { + return { + format: 'json', + content: javaDocGrammar + }; + } + }); + const javaGrammar = require('../../data/java.tmLanguage.json'); + registry.registerTextmateGrammarScope(this.javaScope, { + async getGrammarDefinition() { + return { + format: 'json', + content: javaGrammar + }; + } + }); + registry.mapLanguageIdToTextmateGrammar(this.id, this.javaScope); + } +} diff --git a/packages/textmate-grammars/src/browser/textmate-grammars-frontend-module.ts b/packages/textmate-grammars/src/browser/textmate-grammars-frontend-module.ts index 7d1d7530554c9..ab73c9bcfb431 100644 --- a/packages/textmate-grammars/src/browser/textmate-grammars-frontend-module.ts +++ b/packages/textmate-grammars/src/browser/textmate-grammars-frontend-module.ts @@ -46,6 +46,7 @@ import { ShellContribution } from './shell'; import { TclContribution } from './tcl'; import { XmlContribution } from './xml'; import { XslContribution } from './xsl'; +import { JavaContribution } from './java'; import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser/textmate/textmate-contribution'; export default new ContainerModule(bind => { @@ -141,4 +142,7 @@ export default new ContainerModule(bind => { bind(XslContribution).toSelf().inSingletonScope(); bind(LanguageGrammarDefinitionContribution).toService(XslContribution); + + bind(JavaContribution).toSelf().inSingletonScope(); + bind(LanguageGrammarDefinitionContribution).toService(JavaContribution); });