mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 09:20:10 +01:00
Run prettier
This commit is contained in:
parent
9b90326796
commit
5ebacc725f
17 changed files with 2479 additions and 2105 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -6,4 +6,4 @@
|
|||
"**/release": true,
|
||||
"**/out": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
LICENSE.md
42
LICENSE.md
|
|
@ -1,21 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Microsoft Corporation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
|
|||
72
README.md
72
README.md
|
|
@ -1,35 +1,37 @@
|
|||
# Monaco CSS
|
||||
|
||||
CSS language plugin for the Monaco Editor. It provides the following features when editing CSS, LESS and SCSS files:
|
||||
* Code completion
|
||||
* Hovers
|
||||
* Validation: Syntax errors and linting
|
||||
* Find definition, references & highlights for symbols in the same file
|
||||
* Document Symbols
|
||||
* Color Decorators
|
||||
|
||||
Linting an be configured through the API. See [here](https://github.com/Microsoft/monaco-css/blob/master/src/monaco.d.ts) for the API that the
|
||||
CSS plugin offers to configure the CSS/LESS/SCSS language support.
|
||||
|
||||
Internally the CSS plugin uses the [vscode-css-languageservice](https://github.com/Microsoft/vscode-css-languageservice)
|
||||
node module, providing the implementation of the functionally listed above. The same module is also used
|
||||
in [Visual Studio Code](https://github.com/Microsoft/vscode) to power the CSS, LESS and SCSS editing experience.
|
||||
|
||||
## Issues
|
||||
|
||||
Please file issues concering `monaco-css` in the [`monaco-editor` repository](https://github.com/Microsoft/monaco-editor/issues).
|
||||
|
||||
## Installing
|
||||
|
||||
This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module.
|
||||
|
||||
## Development
|
||||
|
||||
* `npm install .`
|
||||
* compile with `npm run compile`
|
||||
* watch with `npm run watch`
|
||||
* `npm run prepublishOnly`
|
||||
* open `$/monaco-css/test/index.html` in your favorite browser.
|
||||
|
||||
## License
|
||||
[MIT](https://github.com/Microsoft/monaco-css/blob/master/LICENSE.md)
|
||||
# Monaco CSS
|
||||
|
||||
CSS language plugin for the Monaco Editor. It provides the following features when editing CSS, LESS and SCSS files:
|
||||
|
||||
- Code completion
|
||||
- Hovers
|
||||
- Validation: Syntax errors and linting
|
||||
- Find definition, references & highlights for symbols in the same file
|
||||
- Document Symbols
|
||||
- Color Decorators
|
||||
|
||||
Linting an be configured through the API. See [here](https://github.com/Microsoft/monaco-css/blob/master/src/monaco.d.ts) for the API that the
|
||||
CSS plugin offers to configure the CSS/LESS/SCSS language support.
|
||||
|
||||
Internally the CSS plugin uses the [vscode-css-languageservice](https://github.com/Microsoft/vscode-css-languageservice)
|
||||
node module, providing the implementation of the functionally listed above. The same module is also used
|
||||
in [Visual Studio Code](https://github.com/Microsoft/vscode) to power the CSS, LESS and SCSS editing experience.
|
||||
|
||||
## Issues
|
||||
|
||||
Please file issues concering `monaco-css` in the [`monaco-editor` repository](https://github.com/Microsoft/monaco-editor/issues).
|
||||
|
||||
## Installing
|
||||
|
||||
This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module.
|
||||
|
||||
## Development
|
||||
|
||||
- `npm install .`
|
||||
- compile with `npm run compile`
|
||||
- watch with `npm run watch`
|
||||
- `npm run prepublishOnly`
|
||||
- open `$/monaco-css/test/index.html` in your favorite browser.
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/Microsoft/monaco-css/blob/master/LICENSE.md)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const requirejs = require('requirejs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const Terser = require("terser");
|
||||
const Terser = require('terser');
|
||||
const helpers = require('monaco-plugin-helpers');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '..');
|
||||
|
|
@ -25,51 +25,77 @@ bundleOne('cssMode', ['vs/language/css/monaco.contribution']);
|
|||
bundleOne('cssWorker');
|
||||
|
||||
function bundleOne(moduleId, exclude) {
|
||||
requirejs.optimize({
|
||||
baseUrl: 'out/amd/',
|
||||
name: 'vs/language/css/' + moduleId,
|
||||
out: 'release/dev/' + moduleId + '.js',
|
||||
exclude: exclude,
|
||||
paths: {
|
||||
'vs/language/css': REPO_ROOT + '/out/amd',
|
||||
'vs/language/css/fillers/monaco-editor-core':
|
||||
requirejs.optimize(
|
||||
{
|
||||
baseUrl: 'out/amd/',
|
||||
name: 'vs/language/css/' + moduleId,
|
||||
out: 'release/dev/' + moduleId + '.js',
|
||||
exclude: exclude,
|
||||
paths: {
|
||||
'vs/language/css': REPO_ROOT + '/out/amd',
|
||||
'vs/language/css/fillers/monaco-editor-core':
|
||||
REPO_ROOT + '/out/amd/fillers/monaco-editor-core-amd'
|
||||
},
|
||||
optimize: 'none',
|
||||
packages: [
|
||||
{
|
||||
name: 'vscode-css-languageservice',
|
||||
location: path.join(
|
||||
REPO_ROOT,
|
||||
'node_modules/vscode-css-languageservice/lib/umd'
|
||||
),
|
||||
main: 'cssLanguageService'
|
||||
},
|
||||
{
|
||||
name: 'vscode-languageserver-types',
|
||||
location: path.join(
|
||||
REPO_ROOT,
|
||||
'node_modules/vscode-languageserver-types/lib/umd'
|
||||
),
|
||||
main: 'main'
|
||||
},
|
||||
{
|
||||
name: 'vscode-languageserver-textdocument',
|
||||
location: path.join(
|
||||
REPO_ROOT,
|
||||
'node_modules/vscode-languageserver-textdocument/lib/umd'
|
||||
),
|
||||
main: 'main'
|
||||
},
|
||||
{
|
||||
name: 'vscode-uri',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
|
||||
main: 'index'
|
||||
},
|
||||
{
|
||||
name: 'vscode-nls',
|
||||
location: path.join(REPO_ROOT, '/out/amd/fillers'),
|
||||
main: 'vscode-nls'
|
||||
}
|
||||
]
|
||||
},
|
||||
optimize: 'none',
|
||||
packages: [{
|
||||
name: 'vscode-css-languageservice',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-css-languageservice/lib/umd'),
|
||||
main: 'cssLanguageService'
|
||||
}, {
|
||||
name: 'vscode-languageserver-types',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-types/lib/umd'),
|
||||
main: 'main'
|
||||
}, {
|
||||
name: 'vscode-languageserver-textdocument',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-textdocument/lib/umd'),
|
||||
main: 'main'
|
||||
}, {
|
||||
name: 'vscode-uri',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
|
||||
main: 'index'
|
||||
}, {
|
||||
name: 'vscode-nls',
|
||||
location: path.join(REPO_ROOT, '/out/amd/fillers'),
|
||||
main: 'vscode-nls'
|
||||
}]
|
||||
}, async function (buildResponse) {
|
||||
const devFilePath = path.join(REPO_ROOT, 'release/dev/' + moduleId + '.js');
|
||||
const minFilePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js');
|
||||
const fileContents = fs.readFileSync(devFilePath).toString();
|
||||
console.log();
|
||||
console.log(`Minifying ${devFilePath}...`);
|
||||
const result = await Terser.minify(fileContents, {
|
||||
output: {
|
||||
comments: 'some'
|
||||
}
|
||||
});
|
||||
console.log(`Done minifying ${devFilePath}.`);
|
||||
try { fs.mkdirSync(path.join(REPO_ROOT, 'release/min')) } catch (err) { }
|
||||
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
|
||||
})
|
||||
async function (buildResponse) {
|
||||
const devFilePath = path.join(
|
||||
REPO_ROOT,
|
||||
'release/dev/' + moduleId + '.js'
|
||||
);
|
||||
const minFilePath = path.join(
|
||||
REPO_ROOT,
|
||||
'release/min/' + moduleId + '.js'
|
||||
);
|
||||
const fileContents = fs.readFileSync(devFilePath).toString();
|
||||
console.log();
|
||||
console.log(`Minifying ${devFilePath}...`);
|
||||
const result = await Terser.minify(fileContents, {
|
||||
output: {
|
||||
comments: 'some'
|
||||
}
|
||||
});
|
||||
console.log(`Done minifying ${devFilePath}.`);
|
||||
try {
|
||||
fs.mkdirSync(path.join(REPO_ROOT, 'release/min'));
|
||||
} catch (err) {}
|
||||
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ const REPO_ROOT = path.join(__dirname, '../');
|
|||
const SRC_PATH = path.join(REPO_ROOT, 'out/amd/monaco.contribution.d.ts');
|
||||
const DST_PATH = path.join(REPO_ROOT, 'monaco.d.ts');
|
||||
|
||||
const lines = fs.readFileSync(SRC_PATH).toString().split(/\r\n|\r|\n/);
|
||||
const lines = fs
|
||||
.readFileSync(SRC_PATH)
|
||||
.toString()
|
||||
.split(/\r\n|\r|\n/);
|
||||
let result = [
|
||||
`/*---------------------------------------------------------------------------------------------`,
|
||||
` * Copyright (c) Microsoft Corporation. All rights reserved.`,
|
||||
|
|
|
|||
|
|
@ -12,19 +12,13 @@ helpers.packageESM({
|
|||
repoRoot: REPO_ROOT,
|
||||
esmSource: 'out/esm',
|
||||
esmDestination: 'release/esm',
|
||||
entryPoints: [
|
||||
'monaco.contribution.js',
|
||||
'cssMode.js',
|
||||
'css.worker.js',
|
||||
],
|
||||
entryPoints: ['monaco.contribution.js', 'cssMode.js', 'css.worker.js'],
|
||||
resolveAlias: {
|
||||
'vscode-nls': path.join(REPO_ROOT, "out/esm/fillers/vscode-nls.js")
|
||||
'vscode-nls': path.join(REPO_ROOT, 'out/esm/fillers/vscode-nls.js')
|
||||
},
|
||||
resolveSkip: [
|
||||
'monaco-editor-core'
|
||||
],
|
||||
resolveSkip: ['monaco-editor-core'],
|
||||
destinationFolderSimplification: {
|
||||
'node_modules': '_deps',
|
||||
node_modules: '_deps',
|
||||
'vscode-languageserver-types/lib/esm': 'vscode-languageserver-types',
|
||||
'vscode-uri/lib/esm': 'vscode-uri',
|
||||
'vscode-css-languageservice/lib/esm': 'vscode-css-languageservice'
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@ import { CSSWorker } from './cssWorker';
|
|||
self.onmessage = () => {
|
||||
// ignore the first message
|
||||
worker.initialize((ctx, createData) => {
|
||||
return new CSSWorker(ctx, createData)
|
||||
return new CSSWorker(ctx, createData);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
213
src/cssMode.ts
213
src/cssMode.ts
|
|
@ -1,81 +1,132 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { WorkerManager } from './workerManager';
|
||||
import type { CSSWorker } from './cssWorker';
|
||||
import { LanguageServiceDefaults } from './monaco.contribution';
|
||||
import * as languageFeatures from './languageFeatures';
|
||||
import { Uri, IDisposable, languages } from './fillers/monaco-editor-core';
|
||||
|
||||
export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
||||
|
||||
const disposables: IDisposable[] = [];
|
||||
const providers: IDisposable[] = [];
|
||||
|
||||
const client = new WorkerManager(defaults);
|
||||
disposables.push(client);
|
||||
|
||||
const worker: languageFeatures.WorkerAccessor = (...uris: Uri[]): Promise<CSSWorker> => {
|
||||
return client.getLanguageServiceWorker(...uris);
|
||||
};
|
||||
|
||||
|
||||
function registerProviders(): void {
|
||||
const { languageId, modeConfiguration } = defaults;
|
||||
|
||||
disposeAll(providers);
|
||||
|
||||
if (modeConfiguration.completionItems) {
|
||||
providers.push(languages.registerCompletionItemProvider(languageId, new languageFeatures.CompletionAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.hovers) {
|
||||
providers.push(languages.registerHoverProvider(languageId, new languageFeatures.HoverAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.documentHighlights) {
|
||||
providers.push(languages.registerDocumentHighlightProvider(languageId, new languageFeatures.DocumentHighlightAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.definitions) {
|
||||
providers.push(languages.registerDefinitionProvider(languageId, new languageFeatures.DefinitionAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.references) {
|
||||
providers.push(languages.registerReferenceProvider(languageId, new languageFeatures.ReferenceAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.documentSymbols) {
|
||||
providers.push(languages.registerDocumentSymbolProvider(languageId, new languageFeatures.DocumentSymbolAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.rename) {
|
||||
providers.push(languages.registerRenameProvider(languageId, new languageFeatures.RenameAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.colors) {
|
||||
providers.push(languages.registerColorProvider(languageId, new languageFeatures.DocumentColorAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.foldingRanges) {
|
||||
providers.push(languages.registerFoldingRangeProvider(languageId, new languageFeatures.FoldingRangeAdapter(worker)));
|
||||
}
|
||||
if (modeConfiguration.diagnostics) {
|
||||
providers.push(new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults));
|
||||
}
|
||||
if (modeConfiguration.selectionRanges) {
|
||||
providers.push(languages.registerSelectionRangeProvider(languageId, new languageFeatures.SelectionRangeAdapter(worker)));
|
||||
}
|
||||
}
|
||||
|
||||
registerProviders();
|
||||
|
||||
|
||||
disposables.push(asDisposable(providers));
|
||||
|
||||
return asDisposable(disposables);
|
||||
}
|
||||
|
||||
function asDisposable(disposables: IDisposable[]): IDisposable {
|
||||
return { dispose: () => disposeAll(disposables) };
|
||||
}
|
||||
|
||||
function disposeAll(disposables: IDisposable[]) {
|
||||
while (disposables.length) {
|
||||
disposables.pop().dispose();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { WorkerManager } from './workerManager';
|
||||
import type { CSSWorker } from './cssWorker';
|
||||
import { LanguageServiceDefaults } from './monaco.contribution';
|
||||
import * as languageFeatures from './languageFeatures';
|
||||
import { Uri, IDisposable, languages } from './fillers/monaco-editor-core';
|
||||
|
||||
export function setupMode(defaults: LanguageServiceDefaults): IDisposable {
|
||||
const disposables: IDisposable[] = [];
|
||||
const providers: IDisposable[] = [];
|
||||
|
||||
const client = new WorkerManager(defaults);
|
||||
disposables.push(client);
|
||||
|
||||
const worker: languageFeatures.WorkerAccessor = (
|
||||
...uris: Uri[]
|
||||
): Promise<CSSWorker> => {
|
||||
return client.getLanguageServiceWorker(...uris);
|
||||
};
|
||||
|
||||
function registerProviders(): void {
|
||||
const { languageId, modeConfiguration } = defaults;
|
||||
|
||||
disposeAll(providers);
|
||||
|
||||
if (modeConfiguration.completionItems) {
|
||||
providers.push(
|
||||
languages.registerCompletionItemProvider(
|
||||
languageId,
|
||||
new languageFeatures.CompletionAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.hovers) {
|
||||
providers.push(
|
||||
languages.registerHoverProvider(
|
||||
languageId,
|
||||
new languageFeatures.HoverAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.documentHighlights) {
|
||||
providers.push(
|
||||
languages.registerDocumentHighlightProvider(
|
||||
languageId,
|
||||
new languageFeatures.DocumentHighlightAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.definitions) {
|
||||
providers.push(
|
||||
languages.registerDefinitionProvider(
|
||||
languageId,
|
||||
new languageFeatures.DefinitionAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.references) {
|
||||
providers.push(
|
||||
languages.registerReferenceProvider(
|
||||
languageId,
|
||||
new languageFeatures.ReferenceAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.documentSymbols) {
|
||||
providers.push(
|
||||
languages.registerDocumentSymbolProvider(
|
||||
languageId,
|
||||
new languageFeatures.DocumentSymbolAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.rename) {
|
||||
providers.push(
|
||||
languages.registerRenameProvider(
|
||||
languageId,
|
||||
new languageFeatures.RenameAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.colors) {
|
||||
providers.push(
|
||||
languages.registerColorProvider(
|
||||
languageId,
|
||||
new languageFeatures.DocumentColorAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.foldingRanges) {
|
||||
providers.push(
|
||||
languages.registerFoldingRangeProvider(
|
||||
languageId,
|
||||
new languageFeatures.FoldingRangeAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.diagnostics) {
|
||||
providers.push(
|
||||
new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration.selectionRanges) {
|
||||
providers.push(
|
||||
languages.registerSelectionRangeProvider(
|
||||
languageId,
|
||||
new languageFeatures.SelectionRangeAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
registerProviders();
|
||||
|
||||
disposables.push(asDisposable(providers));
|
||||
|
||||
return asDisposable(disposables);
|
||||
}
|
||||
|
||||
function asDisposable(disposables: IDisposable[]): IDisposable {
|
||||
return { dispose: () => disposeAll(disposables) };
|
||||
}
|
||||
|
||||
function disposeAll(disposables: IDisposable[]) {
|
||||
while (disposables.length) {
|
||||
disposables.pop().dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
364
src/cssWorker.ts
364
src/cssWorker.ts
|
|
@ -1,138 +1,226 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type { worker } from './fillers/monaco-editor-core';
|
||||
import * as cssService from 'vscode-css-languageservice';
|
||||
|
||||
export class CSSWorker {
|
||||
|
||||
// --- model sync -----------------------
|
||||
|
||||
private _ctx: worker.IWorkerContext;
|
||||
private _languageService: cssService.LanguageService;
|
||||
private _languageSettings: cssService.LanguageSettings;
|
||||
private _languageId: string;
|
||||
|
||||
constructor(ctx: worker.IWorkerContext, createData: ICreateData) {
|
||||
this._ctx = ctx;
|
||||
this._languageSettings = createData.languageSettings;
|
||||
this._languageId = createData.languageId;
|
||||
switch (this._languageId) {
|
||||
case 'css':
|
||||
this._languageService = cssService.getCSSLanguageService();
|
||||
break;
|
||||
case 'less':
|
||||
this._languageService = cssService.getLESSLanguageService();
|
||||
break;
|
||||
case 'scss':
|
||||
this._languageService = cssService.getSCSSLanguageService();
|
||||
break;
|
||||
default:
|
||||
throw new Error('Invalid language id: ' + this._languageId);
|
||||
}
|
||||
this._languageService.configure(this._languageSettings);
|
||||
}
|
||||
|
||||
// --- language service host ---------------
|
||||
|
||||
async doValidation(uri: string): Promise<cssService.Diagnostic[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (document) {
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let diagnostics = this._languageService.doValidation(document, stylesheet);
|
||||
return Promise.resolve(diagnostics)
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
async doComplete(uri: string, position: cssService.Position): Promise<cssService.CompletionList> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let completions = this._languageService.doComplete(document, position, stylesheet);
|
||||
return Promise.resolve(completions);
|
||||
}
|
||||
async doHover(uri: string, position: cssService.Position): Promise<cssService.Hover> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let hover = this._languageService.doHover(document, position, stylesheet);
|
||||
return Promise.resolve(hover);
|
||||
}
|
||||
async findDefinition(uri: string, position: cssService.Position): Promise<cssService.Location> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let definition = this._languageService.findDefinition(document, position, stylesheet);
|
||||
return Promise.resolve(definition);
|
||||
}
|
||||
async findReferences(uri: string, position: cssService.Position): Promise<cssService.Location[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let references = this._languageService.findReferences(document, position, stylesheet);
|
||||
return Promise.resolve(references);
|
||||
}
|
||||
async findDocumentHighlights(uri: string, position: cssService.Position): Promise<cssService.DocumentHighlight[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let highlights = this._languageService.findDocumentHighlights(document, position, stylesheet);
|
||||
return Promise.resolve(highlights);
|
||||
}
|
||||
async findDocumentSymbols(uri: string): Promise<cssService.SymbolInformation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let symbols = this._languageService.findDocumentSymbols(document, stylesheet);
|
||||
return Promise.resolve(symbols);
|
||||
}
|
||||
async doCodeActions(uri: string, range: cssService.Range, context: cssService.CodeActionContext): Promise<cssService.Command[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let actions = this._languageService.doCodeActions(document, range, context, stylesheet);
|
||||
return Promise.resolve(actions);
|
||||
}
|
||||
async findDocumentColors(uri: string): Promise<cssService.ColorInformation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
|
||||
return Promise.resolve(colorSymbols);
|
||||
}
|
||||
async getColorPresentations(uri: string, color: cssService.Color, range: cssService.Range): Promise<cssService.ColorPresentation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let colorPresentations = this._languageService.getColorPresentations(document, stylesheet, color, range);
|
||||
return Promise.resolve(colorPresentations);
|
||||
}
|
||||
async getFoldingRanges(uri: string, context?: { rangeLimit?: number; }): Promise<cssService.FoldingRange[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let ranges = this._languageService.getFoldingRanges(document, context);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
async getSelectionRanges(uri: string, positions: cssService.Position[]): Promise<cssService.SelectionRange[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let ranges = this._languageService.getSelectionRanges(document, positions, stylesheet);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
async doRename(uri: string, position: cssService.Position, newName: string): Promise<cssService.WorkspaceEdit> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let renames = this._languageService.doRename(document, position, newName, stylesheet);
|
||||
return Promise.resolve(renames);
|
||||
}
|
||||
private _getTextDocument(uri: string): cssService.TextDocument {
|
||||
let models = this._ctx.getMirrorModels();
|
||||
for (let model of models) {
|
||||
if (model.uri.toString() === uri) {
|
||||
return cssService.TextDocument.create(uri, this._languageId, model.version, model.getValue());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ICreateData {
|
||||
languageId: string;
|
||||
languageSettings: cssService.LanguageSettings;
|
||||
}
|
||||
|
||||
export function create(ctx: worker.IWorkerContext, createData: ICreateData): CSSWorker {
|
||||
return new CSSWorker(ctx, createData);
|
||||
}
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import type { worker } from './fillers/monaco-editor-core';
|
||||
import * as cssService from 'vscode-css-languageservice';
|
||||
|
||||
export class CSSWorker {
|
||||
// --- model sync -----------------------
|
||||
|
||||
private _ctx: worker.IWorkerContext;
|
||||
private _languageService: cssService.LanguageService;
|
||||
private _languageSettings: cssService.LanguageSettings;
|
||||
private _languageId: string;
|
||||
|
||||
constructor(ctx: worker.IWorkerContext, createData: ICreateData) {
|
||||
this._ctx = ctx;
|
||||
this._languageSettings = createData.languageSettings;
|
||||
this._languageId = createData.languageId;
|
||||
switch (this._languageId) {
|
||||
case 'css':
|
||||
this._languageService = cssService.getCSSLanguageService();
|
||||
break;
|
||||
case 'less':
|
||||
this._languageService = cssService.getLESSLanguageService();
|
||||
break;
|
||||
case 'scss':
|
||||
this._languageService = cssService.getSCSSLanguageService();
|
||||
break;
|
||||
default:
|
||||
throw new Error('Invalid language id: ' + this._languageId);
|
||||
}
|
||||
this._languageService.configure(this._languageSettings);
|
||||
}
|
||||
|
||||
// --- language service host ---------------
|
||||
|
||||
async doValidation(uri: string): Promise<cssService.Diagnostic[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (document) {
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let diagnostics = this._languageService.doValidation(
|
||||
document,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(diagnostics);
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
async doComplete(
|
||||
uri: string,
|
||||
position: cssService.Position
|
||||
): Promise<cssService.CompletionList> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let completions = this._languageService.doComplete(
|
||||
document,
|
||||
position,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(completions);
|
||||
}
|
||||
async doHover(
|
||||
uri: string,
|
||||
position: cssService.Position
|
||||
): Promise<cssService.Hover> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let hover = this._languageService.doHover(document, position, stylesheet);
|
||||
return Promise.resolve(hover);
|
||||
}
|
||||
async findDefinition(
|
||||
uri: string,
|
||||
position: cssService.Position
|
||||
): Promise<cssService.Location> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let definition = this._languageService.findDefinition(
|
||||
document,
|
||||
position,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(definition);
|
||||
}
|
||||
async findReferences(
|
||||
uri: string,
|
||||
position: cssService.Position
|
||||
): Promise<cssService.Location[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let references = this._languageService.findReferences(
|
||||
document,
|
||||
position,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(references);
|
||||
}
|
||||
async findDocumentHighlights(
|
||||
uri: string,
|
||||
position: cssService.Position
|
||||
): Promise<cssService.DocumentHighlight[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let highlights = this._languageService.findDocumentHighlights(
|
||||
document,
|
||||
position,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(highlights);
|
||||
}
|
||||
async findDocumentSymbols(
|
||||
uri: string
|
||||
): Promise<cssService.SymbolInformation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let symbols = this._languageService.findDocumentSymbols(
|
||||
document,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(symbols);
|
||||
}
|
||||
async doCodeActions(
|
||||
uri: string,
|
||||
range: cssService.Range,
|
||||
context: cssService.CodeActionContext
|
||||
): Promise<cssService.Command[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let actions = this._languageService.doCodeActions(
|
||||
document,
|
||||
range,
|
||||
context,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(actions);
|
||||
}
|
||||
async findDocumentColors(
|
||||
uri: string
|
||||
): Promise<cssService.ColorInformation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let colorSymbols = this._languageService.findDocumentColors(
|
||||
document,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(colorSymbols);
|
||||
}
|
||||
async getColorPresentations(
|
||||
uri: string,
|
||||
color: cssService.Color,
|
||||
range: cssService.Range
|
||||
): Promise<cssService.ColorPresentation[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let colorPresentations = this._languageService.getColorPresentations(
|
||||
document,
|
||||
stylesheet,
|
||||
color,
|
||||
range
|
||||
);
|
||||
return Promise.resolve(colorPresentations);
|
||||
}
|
||||
async getFoldingRanges(
|
||||
uri: string,
|
||||
context?: { rangeLimit?: number }
|
||||
): Promise<cssService.FoldingRange[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let ranges = this._languageService.getFoldingRanges(document, context);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
async getSelectionRanges(
|
||||
uri: string,
|
||||
positions: cssService.Position[]
|
||||
): Promise<cssService.SelectionRange[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let ranges = this._languageService.getSelectionRanges(
|
||||
document,
|
||||
positions,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
async doRename(
|
||||
uri: string,
|
||||
position: cssService.Position,
|
||||
newName: string
|
||||
): Promise<cssService.WorkspaceEdit> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let stylesheet = this._languageService.parseStylesheet(document);
|
||||
let renames = this._languageService.doRename(
|
||||
document,
|
||||
position,
|
||||
newName,
|
||||
stylesheet
|
||||
);
|
||||
return Promise.resolve(renames);
|
||||
}
|
||||
private _getTextDocument(uri: string): cssService.TextDocument {
|
||||
let models = this._ctx.getMirrorModels();
|
||||
for (let model of models) {
|
||||
if (model.uri.toString() === uri) {
|
||||
return cssService.TextDocument.create(
|
||||
uri,
|
||||
this._languageId,
|
||||
model.version,
|
||||
model.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ICreateData {
|
||||
languageId: string;
|
||||
languageSettings: cssService.LanguageSettings;
|
||||
}
|
||||
|
||||
export function create(
|
||||
ctx: worker.IWorkerContext,
|
||||
createData: ICreateData
|
||||
): CSSWorker {
|
||||
return new CSSWorker(ctx, createData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@
|
|||
|
||||
declare var define;
|
||||
|
||||
define([], function() {
|
||||
define([], function () {
|
||||
return (<any>self).monaco;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -33,7 +33,11 @@ function format(message: string, args: any[]): string {
|
|||
return result;
|
||||
}
|
||||
|
||||
function localize(key: string | LocalizeInfo, message: string, ...args: any[]): string {
|
||||
function localize(
|
||||
key: string | LocalizeInfo,
|
||||
message: string,
|
||||
...args: any[]
|
||||
): string {
|
||||
return format(message, args);
|
||||
}
|
||||
|
||||
|
|
@ -43,4 +47,4 @@ export function loadMessageBundle(file?: string): LocalizeFunc {
|
|||
|
||||
export function config(opt?: Options | string): LoadFunc {
|
||||
return loadMessageBundle;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,203 +1,217 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as mode from './cssMode';
|
||||
import { languages, Emitter, IEvent } from './fillers/monaco-editor-core';
|
||||
|
||||
export interface DiagnosticsOptions {
|
||||
readonly validate?: boolean;
|
||||
readonly lint?: {
|
||||
readonly compatibleVendorPrefixes?: 'ignore' | 'warning' | 'error',
|
||||
readonly vendorPrefix?: 'ignore' | 'warning' | 'error',
|
||||
readonly duplicateProperties?: 'ignore' | 'warning' | 'error',
|
||||
readonly emptyRules?: 'ignore' | 'warning' | 'error',
|
||||
readonly importStatement?: 'ignore' | 'warning' | 'error',
|
||||
readonly boxModel?: 'ignore' | 'warning' | 'error',
|
||||
readonly universalSelector?: 'ignore' | 'warning' | 'error',
|
||||
readonly zeroUnits?: 'ignore' | 'warning' | 'error',
|
||||
readonly fontFaceProperties?: 'ignore' | 'warning' | 'error',
|
||||
readonly hexColorLength?: 'ignore' | 'warning' | 'error',
|
||||
readonly argumentsInColorFunction?: 'ignore' | 'warning' | 'error',
|
||||
readonly unknownProperties?: 'ignore' | 'warning' | 'error',
|
||||
readonly ieHack?: 'ignore' | 'warning' | 'error',
|
||||
readonly unknownVendorSpecificProperties?: 'ignore' | 'warning' | 'error',
|
||||
readonly propertyIgnoredDueToDisplay?: 'ignore' | 'warning' | 'error',
|
||||
readonly important?: 'ignore' | 'warning' | 'error',
|
||||
readonly float?: 'ignore' | 'warning' | 'error',
|
||||
readonly idSelector?: 'ignore' | 'warning' | 'error'
|
||||
}
|
||||
}
|
||||
|
||||
export interface ModeConfiguration {
|
||||
/**
|
||||
* Defines whether the built-in completionItemProvider is enabled.
|
||||
*/
|
||||
readonly completionItems?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in hoverProvider is enabled.
|
||||
*/
|
||||
readonly hovers?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in documentSymbolProvider is enabled.
|
||||
*/
|
||||
readonly documentSymbols?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in definitions provider is enabled.
|
||||
*/
|
||||
readonly definitions?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in references provider is enabled.
|
||||
*/
|
||||
readonly references?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in references provider is enabled.
|
||||
*/
|
||||
readonly documentHighlights?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in rename provider is enabled.
|
||||
*/
|
||||
readonly rename?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in color provider is enabled.
|
||||
*/
|
||||
readonly colors?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in foldingRange provider is enabled.
|
||||
*/
|
||||
readonly foldingRanges?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in diagnostic provider is enabled.
|
||||
*/
|
||||
readonly diagnostics?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in selection range provider is enabled.
|
||||
*/
|
||||
readonly selectionRanges?: boolean;
|
||||
|
||||
}
|
||||
|
||||
export interface LanguageServiceDefaults {
|
||||
readonly languageId: string;
|
||||
readonly onDidChange: IEvent<LanguageServiceDefaults>;
|
||||
readonly diagnosticsOptions: DiagnosticsOptions;
|
||||
readonly modeConfiguration: ModeConfiguration;
|
||||
setDiagnosticsOptions(options: DiagnosticsOptions): void;
|
||||
setModeConfiguration(modeConfiguration: ModeConfiguration): void;
|
||||
}
|
||||
|
||||
// --- CSS configuration and defaults ---------
|
||||
|
||||
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||
|
||||
private _onDidChange = new Emitter<LanguageServiceDefaults>();
|
||||
private _diagnosticsOptions: DiagnosticsOptions;
|
||||
private _modeConfiguration: ModeConfiguration;
|
||||
private _languageId: string;
|
||||
|
||||
constructor(languageId: string, diagnosticsOptions: DiagnosticsOptions, modeConfiguration: ModeConfiguration) {
|
||||
this._languageId = languageId;
|
||||
this.setDiagnosticsOptions(diagnosticsOptions);
|
||||
this.setModeConfiguration(modeConfiguration);
|
||||
}
|
||||
|
||||
get onDidChange(): IEvent<LanguageServiceDefaults> {
|
||||
return this._onDidChange.event;
|
||||
}
|
||||
|
||||
get languageId(): string {
|
||||
return this._languageId;
|
||||
}
|
||||
|
||||
get modeConfiguration(): ModeConfiguration {
|
||||
return this._modeConfiguration;
|
||||
}
|
||||
|
||||
get diagnosticsOptions(): DiagnosticsOptions {
|
||||
return this._diagnosticsOptions;
|
||||
}
|
||||
|
||||
setDiagnosticsOptions(options: DiagnosticsOptions): void {
|
||||
this._diagnosticsOptions = options || Object.create(null);
|
||||
this._onDidChange.fire(this);
|
||||
}
|
||||
|
||||
setModeConfiguration(modeConfiguration: ModeConfiguration): void {
|
||||
this._modeConfiguration = modeConfiguration || Object.create(null);
|
||||
this._onDidChange.fire(this);
|
||||
};
|
||||
}
|
||||
|
||||
const diagnosticDefault: Required<DiagnosticsOptions> = {
|
||||
validate: true,
|
||||
lint: {
|
||||
compatibleVendorPrefixes: 'ignore',
|
||||
vendorPrefix: 'warning',
|
||||
duplicateProperties: 'warning',
|
||||
emptyRules: 'warning',
|
||||
importStatement: 'ignore',
|
||||
boxModel: 'ignore',
|
||||
universalSelector: 'ignore',
|
||||
zeroUnits: 'ignore',
|
||||
fontFaceProperties: 'warning',
|
||||
hexColorLength: 'error',
|
||||
argumentsInColorFunction: 'error',
|
||||
unknownProperties: 'warning',
|
||||
ieHack: 'ignore',
|
||||
unknownVendorSpecificProperties: 'ignore',
|
||||
propertyIgnoredDueToDisplay: 'warning',
|
||||
important: 'ignore',
|
||||
float: 'ignore',
|
||||
idSelector: 'ignore'
|
||||
}
|
||||
}
|
||||
|
||||
const modeConfigurationDefault: Required<ModeConfiguration> = {
|
||||
completionItems: true,
|
||||
hovers: true,
|
||||
documentSymbols: true,
|
||||
definitions: true,
|
||||
references: true,
|
||||
documentHighlights: true,
|
||||
rename: true,
|
||||
colors: true,
|
||||
foldingRanges: true,
|
||||
diagnostics: true,
|
||||
selectionRanges: true
|
||||
}
|
||||
|
||||
export const cssDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl('css', diagnosticDefault, modeConfigurationDefault);
|
||||
export const scssDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl('scss', diagnosticDefault, modeConfigurationDefault);
|
||||
export const lessDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl('less', diagnosticDefault, modeConfigurationDefault);
|
||||
|
||||
// export to the global based API
|
||||
(<any>languages).json = { cssDefaults, lessDefaults, scssDefaults };
|
||||
|
||||
// --- Registration to monaco editor ---
|
||||
|
||||
function getMode(): Promise<typeof mode> {
|
||||
return import('./cssMode');
|
||||
}
|
||||
|
||||
languages.onLanguage('less', () => {
|
||||
getMode().then(mode => mode.setupMode(lessDefaults));
|
||||
});
|
||||
|
||||
languages.onLanguage('scss', () => {
|
||||
getMode().then(mode => mode.setupMode(scssDefaults));
|
||||
});
|
||||
|
||||
languages.onLanguage('css', () => {
|
||||
getMode().then(mode => mode.setupMode(cssDefaults));
|
||||
});
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as mode from './cssMode';
|
||||
import { languages, Emitter, IEvent } from './fillers/monaco-editor-core';
|
||||
|
||||
export interface DiagnosticsOptions {
|
||||
readonly validate?: boolean;
|
||||
readonly lint?: {
|
||||
readonly compatibleVendorPrefixes?: 'ignore' | 'warning' | 'error';
|
||||
readonly vendorPrefix?: 'ignore' | 'warning' | 'error';
|
||||
readonly duplicateProperties?: 'ignore' | 'warning' | 'error';
|
||||
readonly emptyRules?: 'ignore' | 'warning' | 'error';
|
||||
readonly importStatement?: 'ignore' | 'warning' | 'error';
|
||||
readonly boxModel?: 'ignore' | 'warning' | 'error';
|
||||
readonly universalSelector?: 'ignore' | 'warning' | 'error';
|
||||
readonly zeroUnits?: 'ignore' | 'warning' | 'error';
|
||||
readonly fontFaceProperties?: 'ignore' | 'warning' | 'error';
|
||||
readonly hexColorLength?: 'ignore' | 'warning' | 'error';
|
||||
readonly argumentsInColorFunction?: 'ignore' | 'warning' | 'error';
|
||||
readonly unknownProperties?: 'ignore' | 'warning' | 'error';
|
||||
readonly ieHack?: 'ignore' | 'warning' | 'error';
|
||||
readonly unknownVendorSpecificProperties?: 'ignore' | 'warning' | 'error';
|
||||
readonly propertyIgnoredDueToDisplay?: 'ignore' | 'warning' | 'error';
|
||||
readonly important?: 'ignore' | 'warning' | 'error';
|
||||
readonly float?: 'ignore' | 'warning' | 'error';
|
||||
readonly idSelector?: 'ignore' | 'warning' | 'error';
|
||||
};
|
||||
}
|
||||
|
||||
export interface ModeConfiguration {
|
||||
/**
|
||||
* Defines whether the built-in completionItemProvider is enabled.
|
||||
*/
|
||||
readonly completionItems?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in hoverProvider is enabled.
|
||||
*/
|
||||
readonly hovers?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in documentSymbolProvider is enabled.
|
||||
*/
|
||||
readonly documentSymbols?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in definitions provider is enabled.
|
||||
*/
|
||||
readonly definitions?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in references provider is enabled.
|
||||
*/
|
||||
readonly references?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in references provider is enabled.
|
||||
*/
|
||||
readonly documentHighlights?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in rename provider is enabled.
|
||||
*/
|
||||
readonly rename?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in color provider is enabled.
|
||||
*/
|
||||
readonly colors?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in foldingRange provider is enabled.
|
||||
*/
|
||||
readonly foldingRanges?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in diagnostic provider is enabled.
|
||||
*/
|
||||
readonly diagnostics?: boolean;
|
||||
|
||||
/**
|
||||
* Defines whether the built-in selection range provider is enabled.
|
||||
*/
|
||||
readonly selectionRanges?: boolean;
|
||||
}
|
||||
|
||||
export interface LanguageServiceDefaults {
|
||||
readonly languageId: string;
|
||||
readonly onDidChange: IEvent<LanguageServiceDefaults>;
|
||||
readonly diagnosticsOptions: DiagnosticsOptions;
|
||||
readonly modeConfiguration: ModeConfiguration;
|
||||
setDiagnosticsOptions(options: DiagnosticsOptions): void;
|
||||
setModeConfiguration(modeConfiguration: ModeConfiguration): void;
|
||||
}
|
||||
|
||||
// --- CSS configuration and defaults ---------
|
||||
|
||||
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||
private _onDidChange = new Emitter<LanguageServiceDefaults>();
|
||||
private _diagnosticsOptions: DiagnosticsOptions;
|
||||
private _modeConfiguration: ModeConfiguration;
|
||||
private _languageId: string;
|
||||
|
||||
constructor(
|
||||
languageId: string,
|
||||
diagnosticsOptions: DiagnosticsOptions,
|
||||
modeConfiguration: ModeConfiguration
|
||||
) {
|
||||
this._languageId = languageId;
|
||||
this.setDiagnosticsOptions(diagnosticsOptions);
|
||||
this.setModeConfiguration(modeConfiguration);
|
||||
}
|
||||
|
||||
get onDidChange(): IEvent<LanguageServiceDefaults> {
|
||||
return this._onDidChange.event;
|
||||
}
|
||||
|
||||
get languageId(): string {
|
||||
return this._languageId;
|
||||
}
|
||||
|
||||
get modeConfiguration(): ModeConfiguration {
|
||||
return this._modeConfiguration;
|
||||
}
|
||||
|
||||
get diagnosticsOptions(): DiagnosticsOptions {
|
||||
return this._diagnosticsOptions;
|
||||
}
|
||||
|
||||
setDiagnosticsOptions(options: DiagnosticsOptions): void {
|
||||
this._diagnosticsOptions = options || Object.create(null);
|
||||
this._onDidChange.fire(this);
|
||||
}
|
||||
|
||||
setModeConfiguration(modeConfiguration: ModeConfiguration): void {
|
||||
this._modeConfiguration = modeConfiguration || Object.create(null);
|
||||
this._onDidChange.fire(this);
|
||||
}
|
||||
}
|
||||
|
||||
const diagnosticDefault: Required<DiagnosticsOptions> = {
|
||||
validate: true,
|
||||
lint: {
|
||||
compatibleVendorPrefixes: 'ignore',
|
||||
vendorPrefix: 'warning',
|
||||
duplicateProperties: 'warning',
|
||||
emptyRules: 'warning',
|
||||
importStatement: 'ignore',
|
||||
boxModel: 'ignore',
|
||||
universalSelector: 'ignore',
|
||||
zeroUnits: 'ignore',
|
||||
fontFaceProperties: 'warning',
|
||||
hexColorLength: 'error',
|
||||
argumentsInColorFunction: 'error',
|
||||
unknownProperties: 'warning',
|
||||
ieHack: 'ignore',
|
||||
unknownVendorSpecificProperties: 'ignore',
|
||||
propertyIgnoredDueToDisplay: 'warning',
|
||||
important: 'ignore',
|
||||
float: 'ignore',
|
||||
idSelector: 'ignore'
|
||||
}
|
||||
};
|
||||
|
||||
const modeConfigurationDefault: Required<ModeConfiguration> = {
|
||||
completionItems: true,
|
||||
hovers: true,
|
||||
documentSymbols: true,
|
||||
definitions: true,
|
||||
references: true,
|
||||
documentHighlights: true,
|
||||
rename: true,
|
||||
colors: true,
|
||||
foldingRanges: true,
|
||||
diagnostics: true,
|
||||
selectionRanges: true
|
||||
};
|
||||
|
||||
export const cssDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
||||
'css',
|
||||
diagnosticDefault,
|
||||
modeConfigurationDefault
|
||||
);
|
||||
export const scssDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
||||
'scss',
|
||||
diagnosticDefault,
|
||||
modeConfigurationDefault
|
||||
);
|
||||
export const lessDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
||||
'less',
|
||||
diagnosticDefault,
|
||||
modeConfigurationDefault
|
||||
);
|
||||
|
||||
// export to the global based API
|
||||
(<any>languages).json = { cssDefaults, lessDefaults, scssDefaults };
|
||||
|
||||
// --- Registration to monaco editor ---
|
||||
|
||||
function getMode(): Promise<typeof mode> {
|
||||
return import('./cssMode');
|
||||
}
|
||||
|
||||
languages.onLanguage('less', () => {
|
||||
getMode().then((mode) => mode.setupMode(lessDefaults));
|
||||
});
|
||||
|
||||
languages.onLanguage('scss', () => {
|
||||
getMode().then((mode) => mode.setupMode(scssDefaults));
|
||||
});
|
||||
|
||||
languages.onLanguage('css', () => {
|
||||
getMode().then((mode) => mode.setupMode(cssDefaults));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../out/esm",
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es5",
|
||||
"es2015.collection",
|
||||
"es2015.promise",
|
||||
"es2015.iterable"
|
||||
]
|
||||
}
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../out/esm",
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es5",
|
||||
"es2015.collection",
|
||||
"es2015.promise",
|
||||
"es2015.iterable"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "amd",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../out/amd",
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es5",
|
||||
"es2015.collection",
|
||||
"es2015.promise",
|
||||
"es2015.iterable"
|
||||
]
|
||||
}
|
||||
"compilerOptions": {
|
||||
"module": "amd",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../out/amd",
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es5",
|
||||
"es2015.collection",
|
||||
"es2015.promise",
|
||||
"es2015.iterable"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,86 +1,92 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { LanguageServiceDefaults } from './monaco.contribution';
|
||||
import type { CSSWorker } from './cssWorker';
|
||||
import { editor, IDisposable, Uri } from './fillers/monaco-editor-core';
|
||||
|
||||
const STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
|
||||
|
||||
export class WorkerManager {
|
||||
|
||||
private _defaults: LanguageServiceDefaults;
|
||||
private _idleCheckInterval: number;
|
||||
private _lastUsedTime: number;
|
||||
private _configChangeListener: IDisposable;
|
||||
|
||||
private _worker: editor.MonacoWebWorker<CSSWorker>;
|
||||
private _client: Promise<CSSWorker>;
|
||||
|
||||
constructor(defaults: LanguageServiceDefaults) {
|
||||
this._defaults = defaults;
|
||||
this._worker = null;
|
||||
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1000);
|
||||
this._lastUsedTime = 0;
|
||||
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
||||
}
|
||||
|
||||
private _stopWorker(): void {
|
||||
if (this._worker) {
|
||||
this._worker.dispose();
|
||||
this._worker = null;
|
||||
}
|
||||
this._client = null;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
clearInterval(this._idleCheckInterval);
|
||||
this._configChangeListener.dispose();
|
||||
this._stopWorker();
|
||||
}
|
||||
|
||||
private _checkIfIdle(): void {
|
||||
if (!this._worker) {
|
||||
return;
|
||||
}
|
||||
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
||||
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
|
||||
this._stopWorker();
|
||||
}
|
||||
}
|
||||
|
||||
private _getClient(): Promise<CSSWorker> {
|
||||
this._lastUsedTime = Date.now();
|
||||
|
||||
if (!this._client) {
|
||||
this._worker = editor.createWebWorker<CSSWorker>({
|
||||
|
||||
// module that exports the create() method and returns a `CSSWorker` instance
|
||||
moduleId: 'vs/language/css/cssWorker',
|
||||
|
||||
label: this._defaults.languageId,
|
||||
|
||||
// passed in to the create() method
|
||||
createData: {
|
||||
languageSettings: this._defaults.diagnosticsOptions,
|
||||
languageId: this._defaults.languageId
|
||||
}
|
||||
});
|
||||
|
||||
this._client = <Promise<CSSWorker>><any>this._worker.getProxy();
|
||||
}
|
||||
|
||||
return this._client;
|
||||
}
|
||||
|
||||
getLanguageServiceWorker(...resources: Uri[]): Promise<CSSWorker> {
|
||||
let _client: CSSWorker;
|
||||
return this._getClient().then((client) => {
|
||||
_client = client
|
||||
}).then(_ => {
|
||||
return this._worker.withSyncedResources(resources)
|
||||
}).then(_ => _client);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { LanguageServiceDefaults } from './monaco.contribution';
|
||||
import type { CSSWorker } from './cssWorker';
|
||||
import { editor, IDisposable, Uri } from './fillers/monaco-editor-core';
|
||||
|
||||
const STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min
|
||||
|
||||
export class WorkerManager {
|
||||
private _defaults: LanguageServiceDefaults;
|
||||
private _idleCheckInterval: number;
|
||||
private _lastUsedTime: number;
|
||||
private _configChangeListener: IDisposable;
|
||||
|
||||
private _worker: editor.MonacoWebWorker<CSSWorker>;
|
||||
private _client: Promise<CSSWorker>;
|
||||
|
||||
constructor(defaults: LanguageServiceDefaults) {
|
||||
this._defaults = defaults;
|
||||
this._worker = null;
|
||||
this._idleCheckInterval = window.setInterval(
|
||||
() => this._checkIfIdle(),
|
||||
30 * 1000
|
||||
);
|
||||
this._lastUsedTime = 0;
|
||||
this._configChangeListener = this._defaults.onDidChange(() =>
|
||||
this._stopWorker()
|
||||
);
|
||||
}
|
||||
|
||||
private _stopWorker(): void {
|
||||
if (this._worker) {
|
||||
this._worker.dispose();
|
||||
this._worker = null;
|
||||
}
|
||||
this._client = null;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
clearInterval(this._idleCheckInterval);
|
||||
this._configChangeListener.dispose();
|
||||
this._stopWorker();
|
||||
}
|
||||
|
||||
private _checkIfIdle(): void {
|
||||
if (!this._worker) {
|
||||
return;
|
||||
}
|
||||
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
||||
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
|
||||
this._stopWorker();
|
||||
}
|
||||
}
|
||||
|
||||
private _getClient(): Promise<CSSWorker> {
|
||||
this._lastUsedTime = Date.now();
|
||||
|
||||
if (!this._client) {
|
||||
this._worker = editor.createWebWorker<CSSWorker>({
|
||||
// module that exports the create() method and returns a `CSSWorker` instance
|
||||
moduleId: 'vs/language/css/cssWorker',
|
||||
|
||||
label: this._defaults.languageId,
|
||||
|
||||
// passed in to the create() method
|
||||
createData: {
|
||||
languageSettings: this._defaults.diagnosticsOptions,
|
||||
languageId: this._defaults.languageId
|
||||
}
|
||||
});
|
||||
|
||||
this._client = <Promise<CSSWorker>>(<any>this._worker.getProxy());
|
||||
}
|
||||
|
||||
return this._client;
|
||||
}
|
||||
|
||||
getLanguageServiceWorker(...resources: Uri[]): Promise<CSSWorker> {
|
||||
let _client: CSSWorker;
|
||||
return this._getClient()
|
||||
.then((client) => {
|
||||
_client = client;
|
||||
})
|
||||
.then((_) => {
|
||||
return this._worker.withSyncedResources(resources);
|
||||
})
|
||||
.then((_) => _client);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1758
test/index.html
1758
test/index.html
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue