Skip to content

Commit

Permalink
[languages][java]Move java grammars from java extension to textmate-g…
Browse files Browse the repository at this point in the history
…rammars

Signed-off-by: Valeriy Svydenko <vsvydenk@redhat.com>
  • Loading branch information
svor authored and Valeriy Svydenko committed Jan 18, 2019
1 parent b9f4d18 commit 6f9a40b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 115 deletions.
6 changes: 0 additions & 6 deletions packages/java/src/browser/java-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -48,6 +44,4 @@ export default new ContainerModule(bind => {
bind(ResourceResolver).toService(JavaResourceResolver);

bind(LabelProviderContribution).to(JavaLabelProviderContribution).inSingletonScope();

bind(LanguageGrammarDefinitionContribution).to(JavaTextmateContribution).inSingletonScope();
});
29 changes: 0 additions & 29 deletions packages/java/src/browser/monaco-contribution/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions packages/textmate-grammars/src/browser/java.ts
Original file line number Diff line number Diff line change
@@ -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.*)|(\\<svg)|(\\<\\!doctype\\s+svg)',
aliases: ['Java', 'java'],
mimetypes: ['text/x-java-source', 'text/x-java']
});
monaco.languages.setLanguageConfiguration(this.id, {
// 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'] },
]
});

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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);
});

0 comments on commit 6f9a40b

Please sign in to comment.