From ad61b155858a9029005b22a4ce9d931bb99d8e5a Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 23 Jun 2016 10:15:16 +0200 Subject: [PATCH] Move language definition and configuration to monaco-languages --- src/cssMode.ts | 80 +------------------------------------- src/monaco.contribution.ts | 24 ++---------- 2 files changed, 4 insertions(+), 100 deletions(-) diff --git a/src/cssMode.ts b/src/cssMode.ts index 724f511e..f03fc206 100644 --- a/src/cssMode.ts +++ b/src/cssMode.ts @@ -13,84 +13,7 @@ import Promise = monaco.Promise; import Uri = monaco.Uri; import IDisposable = monaco.IDisposable; -export function setupCSS(defaults:LanguageServiceDefaultsImpl): void { - const cssLanguageConfiguration: monaco.languages.LanguageConfiguration = { - wordPattern: /(#?-?\d*\.\d\w*%?)|((::|[@#.!:])?[\w-?]+%?)|::|[@#.!:]/g, - - comments: { - blockComment: ['/*', '*/'] - }, - - brackets: [ - ['{', '}'], - ['[', ']'], - ['(', ')'] - ], - - autoClosingPairs: [ - { open: '{', close: '}' }, - { open: '[', close: ']' }, - { open: '(', close: ')' }, - { open: '"', close: '"', notIn: ['string'] }, - { open: '\'', close: '\'', notIn: ['string'] } - ] - }; - - setupMode( - defaults, - cssLanguageConfiguration - ); -} - -export function setupLESS(defaults:LanguageServiceDefaultsImpl): void { - const lessLanguageConfiguration: monaco.languages.LanguageConfiguration = { - wordPattern: /(#?-?\d*\.\d\w*%?)|([@#!.:]?[\w-?]+%?)|[@#!.]/g, - comments: { - blockComment: ['/*', '*/'], - lineComment: '//' - }, - 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'] }, - ] - }; - - setupMode( - defaults, - lessLanguageConfiguration - ); -} - -export function setupSCSS(defaults:LanguageServiceDefaultsImpl): void { - const scssLanguageConfiguration: monaco.languages.LanguageConfiguration = { - wordPattern: /(#?-?\d*\.\d\w*%?)|([@#!.:]?[\w-?]+%?)|[@#!.]/g, - comments: { - blockComment: ['/*', '*/'], - lineComment: '//' - }, - 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'] }, - ] - }; - - setupMode( - defaults, - scssLanguageConfiguration - ); -} - -function setupMode(defaults:LanguageServiceDefaultsImpl, languageConfiguration: monaco.languages.LanguageConfiguration): void { +export function setupMode(defaults:LanguageServiceDefaultsImpl): void { let disposables: IDisposable[] = []; @@ -111,7 +34,6 @@ function setupMode(defaults:LanguageServiceDefaultsImpl, languageConfiguration: disposables.push(monaco.languages.registerDocumentSymbolProvider(languageId, new languageFeatures.DocumentSymbolAdapter(worker))); disposables.push(monaco.languages.registerRenameProvider(languageId, new languageFeatures.RenameAdapter(worker))); disposables.push(new languageFeatures.DiagnostcsAdapter(languageId, worker)); - disposables.push(monaco.languages.setLanguageConfiguration(languageId, languageConfiguration)); } diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index 3cac0b1f..06ea47dc 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -88,32 +88,14 @@ function withMode(callback:(module:typeof mode)=>void): void { require(['vs/language/css/cssMode'], callback); } -monaco.languages.register({ - id: 'less', - extensions: ['.less'], - aliases: ['Less', 'less'], - mimetypes: ['text/x-less', 'text/less'] -}); monaco.languages.onLanguage('less', () => { - withMode((mode) => mode.setupLESS(lessDefaults)); + withMode(mode => mode.setupMode(lessDefaults)); }); -monaco.languages.register({ - id: 'scss', - extensions: ['.scss'], - aliases: ['Sass', 'sass', 'scss'], - mimetypes: ['text/x-scss', 'text/scss'] -}); monaco.languages.onLanguage('scss', () => { - withMode((mode) => mode.setupSCSS(scssDefaults)); + withMode(mode => mode.setupMode(scssDefaults)); }); -monaco.languages.register({ - id: 'css', - extensions: ['.css'], - aliases: ['CSS', 'css'], - mimetypes: ['text/css'] -}); monaco.languages.onLanguage('css', () => { - withMode((mode) => mode.setupCSS(cssDefaults)); + withMode(mode => mode.setupMode(cssDefaults)); });