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