Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #5229: Add language configuration items for js, ts and jsx #5976

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions packages/textmate-grammars/src/browser/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { injectable } from 'inversify';
import { LanguageGrammarDefinitionContribution, TextmateRegistry, getEncodedLanguageId, GrammarDefinition } from '@theia/monaco/lib/browser/textmate';
Expand Down Expand Up @@ -117,6 +121,45 @@ export class JavascriptContribution implements LanguageGrammarDefinitionContribu
}

protected configuration: monaco.languages.LanguageConfiguration = {
// copied and modified from https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/features/languageConfiguration.ts
'indentationRules': {
'decreaseIndentPattern': /^((?!.*?\/\*).*\*\/)?\s*[\}\]].*$/,
'increaseIndentPattern': /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/
},
'wordPattern': /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
'onEnterRules': [
{
// e.g. /** | */
'beforeText': /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
'afterText': /^\s*\*\/$/,
'action': { indentAction: monaco.languages.IndentAction.IndentOutdent, appendText: ' * ' },
},
{
// e.g. /** ...|
'beforeText': /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
'action': { indentAction: monaco.languages.IndentAction.None, appendText: ' * ' },
},
{
// e.g. * ...|
'beforeText': /^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
'action': { indentAction: monaco.languages.IndentAction.None, appendText: '* ' },
},
{
// e.g. */|
'beforeText': /^(\t|[ ])*[ ]\*\/\s*$/,
'action': { indentAction: monaco.languages.IndentAction.None, removeText: 1 },
},
{
// e.g. *-----*/|
'beforeText': /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$/,
'action': { indentAction: monaco.languages.IndentAction.None, removeText: 1 },
},
{
'beforeText': /^\s*(\bcase\s.+:|\bdefault:)$/,
'afterText': /^(?!\s*(\bcase\b|\bdefault\b))/,
'action': { indentAction: monaco.languages.IndentAction.Indent },
}
],
'comments': {
'lineComment': '//',
'blockComment': ['/*', '*/']
Expand Down
31 changes: 31 additions & 0 deletions packages/textmate-grammars/src/browser/jsx-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { injectable } from 'inversify';
import { LanguageGrammarDefinitionContribution, TextmateRegistry } from '@theia/monaco/lib/browser/textmate';

@injectable()
export class JsxTagsContribution implements LanguageGrammarDefinitionContribution {
private readonly id = 'jsx-tags';
// copied and modified from https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/features/languageConfiguration.ts
static EMPTY_ELEMENTS: string[] = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'];

registerTextmateLanguage(registry: TextmateRegistry): void {
this.registerJsxTags();
Expand All @@ -36,6 +42,31 @@ export class JsxTagsContribution implements LanguageGrammarDefinitionContributio
}

protected configuration: monaco.languages.LanguageConfiguration = {
// copied and modified from https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/features/languageConfiguration.ts
'wordPattern': /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,
'onEnterRules': [
{
'beforeText': new RegExp(`<(?!(?:${JsxTagsContribution.EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w\\-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
'afterText': /^<\/([_:\w][_:\w-.\d]*)\s*>$/i,
'action': { indentAction: monaco.languages.IndentAction.IndentOutdent }
},
{
'beforeText': new RegExp(`<(?!(?:${JsxTagsContribution.EMPTY_ELEMENTS.join('|')}))([_:\\w][_:\\w\\-.\\d]*)([^/>]*(?!/)>)[^<]*$`, 'i'),
'action': { indentAction: monaco.languages.IndentAction.Indent }
},
{
// `beforeText` only applies to tokens of a given language. Since we are dealing with jsx-tags,
// make sure we apply to the closing `>` of a tag so that mixed language spans
// such as `<div onclick={1}>` are handled properly.
'beforeText': /^>$/,
'afterText': /^<\/([_:\w][_:\w-.\d]*)\s*>$/i,
'action': { indentAction: monaco.languages.IndentAction.IndentOutdent }
},
{
'beforeText': /^>$/,
'action': { indentAction: monaco.languages.IndentAction.Indent }
},
],
'comments': {
'blockComment': ['{/*', '*/}']
},
Expand Down
43 changes: 43 additions & 0 deletions packages/textmate-grammars/src/browser/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { injectable, inject } from 'inversify';
import { LanguageGrammarDefinitionContribution, TextmateRegistry, GrammarDefinition } from '@theia/monaco/lib/browser/textmate';
Expand Down Expand Up @@ -106,6 +110,45 @@ export class TypescriptContribution implements LanguageGrammarDefinitionContribu
}

protected configuration: monaco.languages.LanguageConfiguration = {
// copied and modified from https://github.com/microsoft/vscode/blob/master/extensions/typescript-language-features/src/features/languageConfiguration.ts
'indentationRules': {
'decreaseIndentPattern': /^((?!.*?\/\*).*\*\/)?\s*[\}\]].*$/,
'increaseIndentPattern': /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/
},
'wordPattern': /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
'onEnterRules': [
{
// e.g. /** | */
'beforeText': /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
'afterText': /^\s*\*\/$/,
'action': { indentAction: monaco.languages.IndentAction.IndentOutdent, appendText: ' * ' },
},
{
// e.g. /** ...|
'beforeText': /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
'action': { indentAction: monaco.languages.IndentAction.None, appendText: ' * ' },
},
{
// e.g. * ...|
'beforeText': /^(\t|[ ])*[ ]\*([ ]([^\*]|\*(?!\/))*)?$/,
'action': { indentAction: monaco.languages.IndentAction.None, appendText: '* ' },
},
{
// e.g. */|
'beforeText': /^(\t|[ ])*[ ]\*\/\s*$/,
'action': { indentAction: monaco.languages.IndentAction.None, removeText: 1 },
},
{
// e.g. *-----*/|
'beforeText': /^(\t|[ ])*[ ]\*[^/]*\*\/\s*$/,
'action': { indentAction: monaco.languages.IndentAction.None, removeText: 1 },
},
{
'beforeText': /^\s*(\bcase\s.+:|\bdefault:)$/,
'afterText': /^(?!\s*(\bcase\b|\bdefault\b))/,
'action': { indentAction: monaco.languages.IndentAction.Indent },
}
],
'comments': {
'lineComment': '//',
'blockComment': ['/*', '*/']
Expand Down