mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
Run prettier
This commit is contained in:
parent
9b90326796
commit
5ebacc725f
17 changed files with 2479 additions and 2105 deletions
24
README.md
24
README.md
|
|
@ -1,12 +1,13 @@
|
||||||
# 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
|
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.
|
CSS plugin offers to configure the CSS/LESS/SCSS language support.
|
||||||
|
|
@ -25,11 +26,12 @@ This npm module is bundled and distributed in the [monaco-editor](https://www.np
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
* `npm install .`
|
- `npm install .`
|
||||||
* compile with `npm run compile`
|
- compile with `npm run compile`
|
||||||
* watch with `npm run watch`
|
- watch with `npm run watch`
|
||||||
* `npm run prepublishOnly`
|
- `npm run prepublishOnly`
|
||||||
* open `$/monaco-css/test/index.html` in your favorite browser.
|
- open `$/monaco-css/test/index.html` in your favorite browser.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](https://github.com/Microsoft/monaco-css/blob/master/LICENSE.md)
|
[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,7 +25,8 @@ 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/',
|
baseUrl: 'out/amd/',
|
||||||
name: 'vs/language/css/' + moduleId,
|
name: 'vs/language/css/' + moduleId,
|
||||||
out: 'release/dev/' + moduleId + '.js',
|
out: 'release/dev/' + moduleId + '.js',
|
||||||
|
|
@ -36,30 +37,52 @@ function bundleOne(moduleId, exclude) {
|
||||||
REPO_ROOT + '/out/amd/fillers/monaco-editor-core-amd'
|
REPO_ROOT + '/out/amd/fillers/monaco-editor-core-amd'
|
||||||
},
|
},
|
||||||
optimize: 'none',
|
optimize: 'none',
|
||||||
packages: [{
|
packages: [
|
||||||
|
{
|
||||||
name: 'vscode-css-languageservice',
|
name: 'vscode-css-languageservice',
|
||||||
location: path.join(REPO_ROOT, 'node_modules/vscode-css-languageservice/lib/umd'),
|
location: path.join(
|
||||||
|
REPO_ROOT,
|
||||||
|
'node_modules/vscode-css-languageservice/lib/umd'
|
||||||
|
),
|
||||||
main: 'cssLanguageService'
|
main: 'cssLanguageService'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'vscode-languageserver-types',
|
name: 'vscode-languageserver-types',
|
||||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-types/lib/umd'),
|
location: path.join(
|
||||||
|
REPO_ROOT,
|
||||||
|
'node_modules/vscode-languageserver-types/lib/umd'
|
||||||
|
),
|
||||||
main: 'main'
|
main: 'main'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'vscode-languageserver-textdocument',
|
name: 'vscode-languageserver-textdocument',
|
||||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-textdocument/lib/umd'),
|
location: path.join(
|
||||||
|
REPO_ROOT,
|
||||||
|
'node_modules/vscode-languageserver-textdocument/lib/umd'
|
||||||
|
),
|
||||||
main: 'main'
|
main: 'main'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'vscode-uri',
|
name: 'vscode-uri',
|
||||||
location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
|
location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
|
||||||
main: 'index'
|
main: 'index'
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
name: 'vscode-nls',
|
name: 'vscode-nls',
|
||||||
location: path.join(REPO_ROOT, '/out/amd/fillers'),
|
location: path.join(REPO_ROOT, '/out/amd/fillers'),
|
||||||
main: 'vscode-nls'
|
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');
|
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();
|
const fileContents = fs.readFileSync(devFilePath).toString();
|
||||||
console.log();
|
console.log();
|
||||||
console.log(`Minifying ${devFilePath}...`);
|
console.log(`Minifying ${devFilePath}...`);
|
||||||
|
|
@ -69,7 +92,10 @@ function bundleOne(moduleId, exclude) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(`Done minifying ${devFilePath}.`);
|
console.log(`Done minifying ${devFilePath}.`);
|
||||||
try { fs.mkdirSync(path.join(REPO_ROOT, 'release/min')) } catch (err) { }
|
try {
|
||||||
|
fs.mkdirSync(path.join(REPO_ROOT, 'release/min'));
|
||||||
|
} catch (err) {}
|
||||||
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
|
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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -10,61 +10,112 @@ 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 = (...uris: Uri[]): Promise<CSSWorker> => {
|
const worker: languageFeatures.WorkerAccessor = (
|
||||||
|
...uris: Uri[]
|
||||||
|
): Promise<CSSWorker> => {
|
||||||
return client.getLanguageServiceWorker(...uris);
|
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(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.CompletionAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.hovers) {
|
if (modeConfiguration.hovers) {
|
||||||
providers.push(languages.registerHoverProvider(languageId, new languageFeatures.HoverAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerHoverProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.HoverAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.documentHighlights) {
|
if (modeConfiguration.documentHighlights) {
|
||||||
providers.push(languages.registerDocumentHighlightProvider(languageId, new languageFeatures.DocumentHighlightAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerDocumentHighlightProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.DocumentHighlightAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.definitions) {
|
if (modeConfiguration.definitions) {
|
||||||
providers.push(languages.registerDefinitionProvider(languageId, new languageFeatures.DefinitionAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerDefinitionProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.DefinitionAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.references) {
|
if (modeConfiguration.references) {
|
||||||
providers.push(languages.registerReferenceProvider(languageId, new languageFeatures.ReferenceAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerReferenceProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.ReferenceAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.documentSymbols) {
|
if (modeConfiguration.documentSymbols) {
|
||||||
providers.push(languages.registerDocumentSymbolProvider(languageId, new languageFeatures.DocumentSymbolAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerDocumentSymbolProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.DocumentSymbolAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.rename) {
|
if (modeConfiguration.rename) {
|
||||||
providers.push(languages.registerRenameProvider(languageId, new languageFeatures.RenameAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerRenameProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.RenameAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.colors) {
|
if (modeConfiguration.colors) {
|
||||||
providers.push(languages.registerColorProvider(languageId, new languageFeatures.DocumentColorAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerColorProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.DocumentColorAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.foldingRanges) {
|
if (modeConfiguration.foldingRanges) {
|
||||||
providers.push(languages.registerFoldingRangeProvider(languageId, new languageFeatures.FoldingRangeAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerFoldingRangeProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.FoldingRangeAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.diagnostics) {
|
if (modeConfiguration.diagnostics) {
|
||||||
providers.push(new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults));
|
providers.push(
|
||||||
|
new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (modeConfiguration.selectionRanges) {
|
if (modeConfiguration.selectionRanges) {
|
||||||
providers.push(languages.registerSelectionRangeProvider(languageId, new languageFeatures.SelectionRangeAdapter(worker)));
|
providers.push(
|
||||||
|
languages.registerSelectionRangeProvider(
|
||||||
|
languageId,
|
||||||
|
new languageFeatures.SelectionRangeAdapter(worker)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerProviders();
|
registerProviders();
|
||||||
|
|
||||||
|
|
||||||
disposables.push(asDisposable(providers));
|
disposables.push(asDisposable(providers));
|
||||||
|
|
||||||
return asDisposable(disposables);
|
return asDisposable(disposables);
|
||||||
|
|
|
||||||
142
src/cssWorker.ts
142
src/cssWorker.ts
|
|
@ -7,7 +7,6 @@ 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;
|
||||||
|
|
@ -41,87 +40,173 @@ export class CSSWorker {
|
||||||
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(document, stylesheet);
|
let diagnostics = this._languageService.doValidation(
|
||||||
return Promise.resolve(diagnostics)
|
document,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
|
return Promise.resolve(diagnostics);
|
||||||
}
|
}
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
async doComplete(uri: string, position: cssService.Position): Promise<cssService.CompletionList> {
|
async doComplete(
|
||||||
|
uri: string,
|
||||||
|
position: cssService.Position
|
||||||
|
): Promise<cssService.CompletionList> {
|
||||||
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(document, position, stylesheet);
|
let completions = this._languageService.doComplete(
|
||||||
|
document,
|
||||||
|
position,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(completions);
|
return Promise.resolve(completions);
|
||||||
}
|
}
|
||||||
async doHover(uri: string, position: cssService.Position): Promise<cssService.Hover> {
|
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 hover = this._languageService.doHover(document, position, stylesheet);
|
let hover = this._languageService.doHover(document, position, stylesheet);
|
||||||
return Promise.resolve(hover);
|
return Promise.resolve(hover);
|
||||||
}
|
}
|
||||||
async findDefinition(uri: string, position: cssService.Position): Promise<cssService.Location> {
|
async findDefinition(
|
||||||
|
uri: string,
|
||||||
|
position: cssService.Position
|
||||||
|
): Promise<cssService.Location> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseStylesheet(document);
|
let stylesheet = this._languageService.parseStylesheet(document);
|
||||||
let definition = this._languageService.findDefinition(document, position, stylesheet);
|
let definition = this._languageService.findDefinition(
|
||||||
|
document,
|
||||||
|
position,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(definition);
|
return Promise.resolve(definition);
|
||||||
}
|
}
|
||||||
async findReferences(uri: string, position: cssService.Position): Promise<cssService.Location[]> {
|
async findReferences(
|
||||||
|
uri: string,
|
||||||
|
position: cssService.Position
|
||||||
|
): Promise<cssService.Location[]> {
|
||||||
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 references = this._languageService.findReferences(
|
||||||
|
document,
|
||||||
|
position,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(references);
|
return Promise.resolve(references);
|
||||||
}
|
}
|
||||||
async findDocumentHighlights(uri: string, position: cssService.Position): Promise<cssService.DocumentHighlight[]> {
|
async findDocumentHighlights(
|
||||||
|
uri: string,
|
||||||
|
position: cssService.Position
|
||||||
|
): Promise<cssService.DocumentHighlight[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseStylesheet(document);
|
let stylesheet = this._languageService.parseStylesheet(document);
|
||||||
let highlights = this._languageService.findDocumentHighlights(document, position, stylesheet);
|
let highlights = this._languageService.findDocumentHighlights(
|
||||||
|
document,
|
||||||
|
position,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(highlights);
|
return Promise.resolve(highlights);
|
||||||
}
|
}
|
||||||
async findDocumentSymbols(uri: string): Promise<cssService.SymbolInformation[]> {
|
async findDocumentSymbols(
|
||||||
|
uri: string
|
||||||
|
): 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 symbols = this._languageService.findDocumentSymbols(document, stylesheet);
|
let symbols = this._languageService.findDocumentSymbols(
|
||||||
|
document,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(symbols);
|
return Promise.resolve(symbols);
|
||||||
}
|
}
|
||||||
async doCodeActions(uri: string, range: cssService.Range, context: cssService.CodeActionContext): Promise<cssService.Command[]> {
|
async doCodeActions(
|
||||||
|
uri: string,
|
||||||
|
range: cssService.Range,
|
||||||
|
context: cssService.CodeActionContext
|
||||||
|
): Promise<cssService.Command[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseStylesheet(document);
|
let stylesheet = this._languageService.parseStylesheet(document);
|
||||||
let actions = this._languageService.doCodeActions(document, range, context, stylesheet);
|
let actions = this._languageService.doCodeActions(
|
||||||
|
document,
|
||||||
|
range,
|
||||||
|
context,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(actions);
|
return Promise.resolve(actions);
|
||||||
}
|
}
|
||||||
async findDocumentColors(uri: string): Promise<cssService.ColorInformation[]> {
|
async findDocumentColors(
|
||||||
|
uri: string
|
||||||
|
): Promise<cssService.ColorInformation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseStylesheet(document);
|
let stylesheet = this._languageService.parseStylesheet(document);
|
||||||
let colorSymbols = this._languageService.findDocumentColors(document, stylesheet);
|
let colorSymbols = this._languageService.findDocumentColors(
|
||||||
|
document,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(colorSymbols);
|
return Promise.resolve(colorSymbols);
|
||||||
}
|
}
|
||||||
async getColorPresentations(uri: string, color: cssService.Color, range: cssService.Range): Promise<cssService.ColorPresentation[]> {
|
async getColorPresentations(
|
||||||
|
uri: string,
|
||||||
|
color: cssService.Color,
|
||||||
|
range: cssService.Range
|
||||||
|
): Promise<cssService.ColorPresentation[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseStylesheet(document);
|
let stylesheet = this._languageService.parseStylesheet(document);
|
||||||
let colorPresentations = this._languageService.getColorPresentations(document, stylesheet, color, range);
|
let colorPresentations = this._languageService.getColorPresentations(
|
||||||
|
document,
|
||||||
|
stylesheet,
|
||||||
|
color,
|
||||||
|
range
|
||||||
|
);
|
||||||
return Promise.resolve(colorPresentations);
|
return Promise.resolve(colorPresentations);
|
||||||
}
|
}
|
||||||
async getFoldingRanges(uri: string, context?: { rangeLimit?: number; }): Promise<cssService.FoldingRange[]> {
|
async getFoldingRanges(
|
||||||
|
uri: string,
|
||||||
|
context?: { rangeLimit?: number }
|
||||||
|
): Promise<cssService.FoldingRange[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let ranges = this._languageService.getFoldingRanges(document, context);
|
let ranges = this._languageService.getFoldingRanges(document, context);
|
||||||
return Promise.resolve(ranges);
|
return Promise.resolve(ranges);
|
||||||
}
|
}
|
||||||
async getSelectionRanges(uri: string, positions: cssService.Position[]): Promise<cssService.SelectionRange[]> {
|
async getSelectionRanges(
|
||||||
|
uri: string,
|
||||||
|
positions: cssService.Position[]
|
||||||
|
): Promise<cssService.SelectionRange[]> {
|
||||||
let document = this._getTextDocument(uri);
|
let document = this._getTextDocument(uri);
|
||||||
let stylesheet = this._languageService.parseStylesheet(document);
|
let stylesheet = this._languageService.parseStylesheet(document);
|
||||||
let ranges = this._languageService.getSelectionRanges(document, positions, stylesheet);
|
let ranges = this._languageService.getSelectionRanges(
|
||||||
|
document,
|
||||||
|
positions,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(ranges);
|
return Promise.resolve(ranges);
|
||||||
}
|
}
|
||||||
async doRename(uri: string, position: cssService.Position, newName: string): Promise<cssService.WorkspaceEdit> {
|
async doRename(
|
||||||
|
uri: string,
|
||||||
|
position: cssService.Position,
|
||||||
|
newName: string
|
||||||
|
): Promise<cssService.WorkspaceEdit> {
|
||||||
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 renames = this._languageService.doRename(
|
||||||
|
document,
|
||||||
|
position,
|
||||||
|
newName,
|
||||||
|
stylesheet
|
||||||
|
);
|
||||||
return Promise.resolve(renames);
|
return Promise.resolve(renames);
|
||||||
}
|
}
|
||||||
private _getTextDocument(uri: string): cssService.TextDocument {
|
private _getTextDocument(uri: string): cssService.TextDocument {
|
||||||
let models = this._ctx.getMirrorModels();
|
let models = this._ctx.getMirrorModels();
|
||||||
for (let model of models) {
|
for (let model of models) {
|
||||||
if (model.uri.toString() === uri) {
|
if (model.uri.toString() === uri) {
|
||||||
return cssService.TextDocument.create(uri, this._languageId, model.version, model.getValue());
|
return cssService.TextDocument.create(
|
||||||
|
uri,
|
||||||
|
this._languageId,
|
||||||
|
model.version,
|
||||||
|
model.getValue()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -133,6 +218,9 @@ export interface ICreateData {
|
||||||
languageSettings: cssService.LanguageSettings;
|
languageSettings: cssService.LanguageSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create(ctx: worker.IWorkerContext, createData: ICreateData): CSSWorker {
|
export function create(
|
||||||
|
ctx: worker.IWorkerContext,
|
||||||
|
createData: ICreateData
|
||||||
|
): CSSWorker {
|
||||||
return new CSSWorker(ctx, createData);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,34 @@
|
||||||
import { LanguageServiceDefaults } from './monaco.contribution';
|
import { LanguageServiceDefaults } from './monaco.contribution';
|
||||||
import type { CSSWorker } from './cssWorker';
|
import type { CSSWorker } from './cssWorker';
|
||||||
import * as cssService from 'vscode-css-languageservice';
|
import * as cssService from 'vscode-css-languageservice';
|
||||||
import { languages, editor, IMarkdownString, Uri, Position, IRange, Range, CancellationToken, IDisposable, MarkerSeverity } from './fillers/monaco-editor-core';
|
import {
|
||||||
|
languages,
|
||||||
|
editor,
|
||||||
|
IMarkdownString,
|
||||||
|
Uri,
|
||||||
|
Position,
|
||||||
|
IRange,
|
||||||
|
Range,
|
||||||
|
CancellationToken,
|
||||||
|
IDisposable,
|
||||||
|
MarkerSeverity
|
||||||
|
} from './fillers/monaco-editor-core';
|
||||||
|
|
||||||
export interface WorkerAccessor {
|
export interface WorkerAccessor {
|
||||||
(first: Uri, ...more: Uri[]): Promise<CSSWorker>
|
(first: Uri, ...more: Uri[]): Promise<CSSWorker>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- diagnostics --- ---
|
// --- diagnostics --- ---
|
||||||
|
|
||||||
export class DiagnosticsAdapter {
|
export class DiagnosticsAdapter {
|
||||||
|
|
||||||
private _disposables: IDisposable[] = [];
|
private _disposables: IDisposable[] = [];
|
||||||
private _listener: { [uri: string]: IDisposable } = Object.create(null);
|
private _listener: { [uri: string]: IDisposable } = Object.create(null);
|
||||||
|
|
||||||
constructor(private _languageId: string, private _worker: WorkerAccessor, defaults: LanguageServiceDefaults) {
|
constructor(
|
||||||
|
private _languageId: string,
|
||||||
|
private _worker: WorkerAccessor,
|
||||||
|
defaults: LanguageServiceDefaults
|
||||||
|
) {
|
||||||
const onModelAdd = (model: editor.IModel): void => {
|
const onModelAdd = (model: editor.IModel): void => {
|
||||||
let modeId = model.getModeId();
|
let modeId = model.getModeId();
|
||||||
if (modeId !== this._languageId) {
|
if (modeId !== this._languageId) {
|
||||||
|
|
@ -29,7 +43,10 @@ export class DiagnosticsAdapter {
|
||||||
let handle: number;
|
let handle: number;
|
||||||
this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
|
this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
|
||||||
window.clearTimeout(handle);
|
window.clearTimeout(handle);
|
||||||
handle = window.setTimeout(() => this._doValidate(model.uri, modeId), 500);
|
handle = window.setTimeout(
|
||||||
|
() => this._doValidate(model.uri, modeId),
|
||||||
|
500
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._doValidate(model.uri, modeId);
|
this._doValidate(model.uri, modeId);
|
||||||
|
|
@ -48,13 +65,15 @@ export class DiagnosticsAdapter {
|
||||||
|
|
||||||
this._disposables.push(editor.onDidCreateModel(onModelAdd));
|
this._disposables.push(editor.onDidCreateModel(onModelAdd));
|
||||||
this._disposables.push(editor.onWillDisposeModel(onModelRemoved));
|
this._disposables.push(editor.onWillDisposeModel(onModelRemoved));
|
||||||
this._disposables.push(editor.onDidChangeModelLanguage(event => {
|
this._disposables.push(
|
||||||
|
editor.onDidChangeModelLanguage((event) => {
|
||||||
onModelRemoved(event.model);
|
onModelRemoved(event.model);
|
||||||
onModelAdd(event.model);
|
onModelAdd(event.model);
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
defaults.onDidChange(_ => {
|
defaults.onDidChange((_) => {
|
||||||
editor.getModels().forEach(model => {
|
editor.getModels().forEach((model) => {
|
||||||
if (model.getModeId() === this._languageId) {
|
if (model.getModeId() === this._languageId) {
|
||||||
onModelRemoved(model);
|
onModelRemoved(model);
|
||||||
onModelAdd(model);
|
onModelAdd(model);
|
||||||
|
|
@ -74,39 +93,49 @@ export class DiagnosticsAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
this._disposables.forEach(d => d && d.dispose());
|
this._disposables.forEach((d) => d && d.dispose());
|
||||||
this._disposables = [];
|
this._disposables = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _doValidate(resource: Uri, languageId: string): void {
|
private _doValidate(resource: Uri, languageId: string): void {
|
||||||
this._worker(resource).then(worker => {
|
this._worker(resource)
|
||||||
|
.then((worker) => {
|
||||||
return worker.doValidation(resource.toString());
|
return worker.doValidation(resource.toString());
|
||||||
}).then(diagnostics => {
|
})
|
||||||
const markers = diagnostics.map(d => toDiagnostics(resource, d));
|
.then((diagnostics) => {
|
||||||
|
const markers = diagnostics.map((d) => toDiagnostics(resource, d));
|
||||||
let model = editor.getModel(resource);
|
let model = editor.getModel(resource);
|
||||||
if (model.getModeId() === languageId) {
|
if (model.getModeId() === languageId) {
|
||||||
editor.setModelMarkers(model, languageId, markers);
|
editor.setModelMarkers(model, languageId, markers);
|
||||||
}
|
}
|
||||||
}).then(undefined, err => {
|
})
|
||||||
|
.then(undefined, (err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function toSeverity(lsSeverity: number): MarkerSeverity {
|
function toSeverity(lsSeverity: number): MarkerSeverity {
|
||||||
switch (lsSeverity) {
|
switch (lsSeverity) {
|
||||||
case cssService.DiagnosticSeverity.Error: return MarkerSeverity.Error;
|
case cssService.DiagnosticSeverity.Error:
|
||||||
case cssService.DiagnosticSeverity.Warning: return MarkerSeverity.Warning;
|
return MarkerSeverity.Error;
|
||||||
case cssService.DiagnosticSeverity.Information: return MarkerSeverity.Info;
|
case cssService.DiagnosticSeverity.Warning:
|
||||||
case cssService.DiagnosticSeverity.Hint: return MarkerSeverity.Hint;
|
return MarkerSeverity.Warning;
|
||||||
|
case cssService.DiagnosticSeverity.Information:
|
||||||
|
return MarkerSeverity.Info;
|
||||||
|
case cssService.DiagnosticSeverity.Hint:
|
||||||
|
return MarkerSeverity.Hint;
|
||||||
default:
|
default:
|
||||||
return MarkerSeverity.Info;
|
return MarkerSeverity.Info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toDiagnostics(resource: Uri, diag: cssService.Diagnostic): editor.IMarkerData {
|
function toDiagnostics(
|
||||||
let code = typeof diag.code === 'number' ? String(diag.code) : <string>diag.code;
|
resource: Uri,
|
||||||
|
diag: cssService.Diagnostic
|
||||||
|
): editor.IMarkerData {
|
||||||
|
let code =
|
||||||
|
typeof diag.code === 'number' ? String(diag.code) : <string>diag.code;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
severity: toSeverity(diag.severity),
|
severity: toSeverity(diag.severity),
|
||||||
|
|
@ -133,74 +162,115 @@ function fromRange(range: IRange): cssService.Range {
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
return { start: { line: range.startLineNumber - 1, character: range.startColumn - 1 }, end: { line: range.endLineNumber - 1, character: range.endColumn - 1 } };
|
return {
|
||||||
|
start: {
|
||||||
|
line: range.startLineNumber - 1,
|
||||||
|
character: range.startColumn - 1
|
||||||
|
},
|
||||||
|
end: { line: range.endLineNumber - 1, character: range.endColumn - 1 }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function toRange(range: cssService.Range): Range {
|
function toRange(range: cssService.Range): Range {
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
|
return new Range(
|
||||||
|
range.start.line + 1,
|
||||||
|
range.start.character + 1,
|
||||||
|
range.end.line + 1,
|
||||||
|
range.end.character + 1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toCompletionItemKind(kind: number): languages.CompletionItemKind {
|
function toCompletionItemKind(kind: number): languages.CompletionItemKind {
|
||||||
let mItemKind = languages.CompletionItemKind;
|
let mItemKind = languages.CompletionItemKind;
|
||||||
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case cssService.CompletionItemKind.Text: return mItemKind.Text;
|
case cssService.CompletionItemKind.Text:
|
||||||
case cssService.CompletionItemKind.Method: return mItemKind.Method;
|
return mItemKind.Text;
|
||||||
case cssService.CompletionItemKind.Function: return mItemKind.Function;
|
case cssService.CompletionItemKind.Method:
|
||||||
case cssService.CompletionItemKind.Constructor: return mItemKind.Constructor;
|
return mItemKind.Method;
|
||||||
case cssService.CompletionItemKind.Field: return mItemKind.Field;
|
case cssService.CompletionItemKind.Function:
|
||||||
case cssService.CompletionItemKind.Variable: return mItemKind.Variable;
|
return mItemKind.Function;
|
||||||
case cssService.CompletionItemKind.Class: return mItemKind.Class;
|
case cssService.CompletionItemKind.Constructor:
|
||||||
case cssService.CompletionItemKind.Interface: return mItemKind.Interface;
|
return mItemKind.Constructor;
|
||||||
case cssService.CompletionItemKind.Module: return mItemKind.Module;
|
case cssService.CompletionItemKind.Field:
|
||||||
case cssService.CompletionItemKind.Property: return mItemKind.Property;
|
return mItemKind.Field;
|
||||||
case cssService.CompletionItemKind.Unit: return mItemKind.Unit;
|
case cssService.CompletionItemKind.Variable:
|
||||||
case cssService.CompletionItemKind.Value: return mItemKind.Value;
|
return mItemKind.Variable;
|
||||||
case cssService.CompletionItemKind.Enum: return mItemKind.Enum;
|
case cssService.CompletionItemKind.Class:
|
||||||
case cssService.CompletionItemKind.Keyword: return mItemKind.Keyword;
|
return mItemKind.Class;
|
||||||
case cssService.CompletionItemKind.Snippet: return mItemKind.Snippet;
|
case cssService.CompletionItemKind.Interface:
|
||||||
case cssService.CompletionItemKind.Color: return mItemKind.Color;
|
return mItemKind.Interface;
|
||||||
case cssService.CompletionItemKind.File: return mItemKind.File;
|
case cssService.CompletionItemKind.Module:
|
||||||
case cssService.CompletionItemKind.Reference: return mItemKind.Reference;
|
return mItemKind.Module;
|
||||||
|
case cssService.CompletionItemKind.Property:
|
||||||
|
return mItemKind.Property;
|
||||||
|
case cssService.CompletionItemKind.Unit:
|
||||||
|
return mItemKind.Unit;
|
||||||
|
case cssService.CompletionItemKind.Value:
|
||||||
|
return mItemKind.Value;
|
||||||
|
case cssService.CompletionItemKind.Enum:
|
||||||
|
return mItemKind.Enum;
|
||||||
|
case cssService.CompletionItemKind.Keyword:
|
||||||
|
return mItemKind.Keyword;
|
||||||
|
case cssService.CompletionItemKind.Snippet:
|
||||||
|
return mItemKind.Snippet;
|
||||||
|
case cssService.CompletionItemKind.Color:
|
||||||
|
return mItemKind.Color;
|
||||||
|
case cssService.CompletionItemKind.File:
|
||||||
|
return mItemKind.File;
|
||||||
|
case cssService.CompletionItemKind.Reference:
|
||||||
|
return mItemKind.Reference;
|
||||||
}
|
}
|
||||||
return mItemKind.Property;
|
return mItemKind.Property;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toTextEdit(textEdit: cssService.TextEdit): editor.ISingleEditOperation {
|
function toTextEdit(
|
||||||
|
textEdit: cssService.TextEdit
|
||||||
|
): editor.ISingleEditOperation {
|
||||||
if (!textEdit) {
|
if (!textEdit) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
range: toRange(textEdit.range),
|
range: toRange(textEdit.range),
|
||||||
text: textEdit.newText
|
text: textEdit.newText
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CompletionAdapter implements languages.CompletionItemProvider {
|
export class CompletionAdapter implements languages.CompletionItemProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
constructor(private _worker: WorkerAccessor) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public get triggerCharacters(): string[] {
|
public get triggerCharacters(): string[] {
|
||||||
return [' ', ':'];
|
return [' ', ':'];
|
||||||
}
|
}
|
||||||
|
|
||||||
provideCompletionItems(model: editor.IReadOnlyModel, position: Position, context: languages.CompletionContext, token: CancellationToken): Promise<languages.CompletionList> {
|
provideCompletionItems(
|
||||||
|
model: editor.IReadOnlyModel,
|
||||||
|
position: Position,
|
||||||
|
context: languages.CompletionContext,
|
||||||
|
token: CancellationToken
|
||||||
|
): Promise<languages.CompletionList> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => {
|
return this._worker(resource)
|
||||||
|
.then((worker) => {
|
||||||
return worker.doComplete(resource.toString(), fromPosition(position));
|
return worker.doComplete(resource.toString(), fromPosition(position));
|
||||||
}).then(info => {
|
})
|
||||||
|
.then((info) => {
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const wordInfo = model.getWordUntilPosition(position);
|
const wordInfo = model.getWordUntilPosition(position);
|
||||||
const wordRange = new Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
|
const wordRange = new Range(
|
||||||
|
position.lineNumber,
|
||||||
|
wordInfo.startColumn,
|
||||||
|
position.lineNumber,
|
||||||
|
wordInfo.endColumn
|
||||||
|
);
|
||||||
|
|
||||||
let items: languages.CompletionItem[] = info.items.map(entry => {
|
let items: languages.CompletionItem[] = info.items.map((entry) => {
|
||||||
let item: languages.CompletionItem = {
|
let item: languages.CompletionItem = {
|
||||||
label: entry.label,
|
label: entry.label,
|
||||||
insertText: entry.insertText || entry.label,
|
insertText: entry.insertText || entry.label,
|
||||||
|
|
@ -209,17 +279,20 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
||||||
documentation: entry.documentation,
|
documentation: entry.documentation,
|
||||||
detail: entry.detail,
|
detail: entry.detail,
|
||||||
range: wordRange,
|
range: wordRange,
|
||||||
kind: toCompletionItemKind(entry.kind),
|
kind: toCompletionItemKind(entry.kind)
|
||||||
};
|
};
|
||||||
if (entry.textEdit) {
|
if (entry.textEdit) {
|
||||||
item.range = toRange(entry.textEdit.range);
|
item.range = toRange(entry.textEdit.range);
|
||||||
item.insertText = entry.textEdit.newText;
|
item.insertText = entry.textEdit.newText;
|
||||||
}
|
}
|
||||||
if (entry.additionalTextEdits) {
|
if (entry.additionalTextEdits) {
|
||||||
item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit)
|
item.additionalTextEdits = entry.additionalTextEdits.map(
|
||||||
|
toTextEdit
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (entry.insertTextFormat === cssService.InsertTextFormat.Snippet) {
|
if (entry.insertTextFormat === cssService.InsertTextFormat.Snippet) {
|
||||||
item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
item.insertTextRules =
|
||||||
|
languages.CompletionItemInsertTextRule.InsertAsSnippet;
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
@ -232,12 +305,17 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function isMarkupContent(thing: any): thing is cssService.MarkupContent {
|
function isMarkupContent(thing: any): thing is cssService.MarkupContent {
|
||||||
return thing && typeof thing === 'object' && typeof (<cssService.MarkupContent>thing).kind === 'string';
|
return (
|
||||||
|
thing &&
|
||||||
|
typeof thing === 'object' &&
|
||||||
|
typeof (<cssService.MarkupContent>thing).kind === 'string'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toMarkdownString(entry: cssService.MarkupContent | cssService.MarkedString): IMarkdownString {
|
function toMarkdownString(
|
||||||
|
entry: cssService.MarkupContent | cssService.MarkedString
|
||||||
|
): IMarkdownString {
|
||||||
if (typeof entry === 'string') {
|
if (typeof entry === 'string') {
|
||||||
return {
|
return {
|
||||||
value: entry
|
value: entry
|
||||||
|
|
@ -257,7 +335,12 @@ function toMarkdownString(entry: cssService.MarkupContent | cssService.MarkedStr
|
||||||
return { value: '```' + entry.language + '\n' + entry.value + '\n```\n' };
|
return { value: '```' + entry.language + '\n' + entry.value + '\n```\n' };
|
||||||
}
|
}
|
||||||
|
|
||||||
function toMarkedStringArray(contents: cssService.MarkupContent | cssService.MarkedString | cssService.MarkedString[]): IMarkdownString[] {
|
function toMarkedStringArray(
|
||||||
|
contents:
|
||||||
|
| cssService.MarkupContent
|
||||||
|
| cssService.MarkedString
|
||||||
|
| cssService.MarkedString[]
|
||||||
|
): IMarkdownString[] {
|
||||||
if (!contents) {
|
if (!contents) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
@ -267,20 +350,23 @@ function toMarkedStringArray(contents: cssService.MarkupContent | cssService.Mar
|
||||||
return [toMarkdownString(contents)];
|
return [toMarkdownString(contents)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- hover ------
|
// --- hover ------
|
||||||
|
|
||||||
export class HoverAdapter implements languages.HoverProvider {
|
export class HoverAdapter implements languages.HoverProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
provideHover(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
position: Position,
|
||||||
provideHover(model: editor.IReadOnlyModel, position: Position, token: CancellationToken): Promise<languages.Hover> {
|
token: CancellationToken
|
||||||
|
): Promise<languages.Hover> {
|
||||||
let resource = model.uri;
|
let resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => {
|
return this._worker(resource)
|
||||||
|
.then((worker) => {
|
||||||
return worker.doHover(resource.toString(), fromPosition(position));
|
return worker.doHover(resource.toString(), fromPosition(position));
|
||||||
}).then(info => {
|
})
|
||||||
|
.then((info) => {
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -294,31 +380,43 @@ export class HoverAdapter implements languages.HoverProvider {
|
||||||
|
|
||||||
// --- document highlights ------
|
// --- document highlights ------
|
||||||
|
|
||||||
function toDocumentHighlightKind(kind: number): languages.DocumentHighlightKind {
|
function toDocumentHighlightKind(
|
||||||
|
kind: number
|
||||||
|
): languages.DocumentHighlightKind {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case cssService.DocumentHighlightKind.Read: return languages.DocumentHighlightKind.Read;
|
case cssService.DocumentHighlightKind.Read:
|
||||||
case cssService.DocumentHighlightKind.Write: return languages.DocumentHighlightKind.Write;
|
return languages.DocumentHighlightKind.Read;
|
||||||
case cssService.DocumentHighlightKind.Text: return languages.DocumentHighlightKind.Text;
|
case cssService.DocumentHighlightKind.Write:
|
||||||
|
return languages.DocumentHighlightKind.Write;
|
||||||
|
case cssService.DocumentHighlightKind.Text:
|
||||||
|
return languages.DocumentHighlightKind.Text;
|
||||||
}
|
}
|
||||||
return languages.DocumentHighlightKind.Text;
|
return languages.DocumentHighlightKind.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class DocumentHighlightAdapter
|
||||||
|
implements languages.DocumentHighlightProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
export class DocumentHighlightAdapter implements languages.DocumentHighlightProvider {
|
public provideDocumentHighlights(
|
||||||
|
model: editor.IReadOnlyModel,
|
||||||
constructor(private _worker: WorkerAccessor) {
|
position: Position,
|
||||||
}
|
token: CancellationToken
|
||||||
|
): Promise<languages.DocumentHighlight[]> {
|
||||||
public provideDocumentHighlights(model: editor.IReadOnlyModel, position: Position, token: CancellationToken): Promise<languages.DocumentHighlight[]> {
|
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => {
|
return this._worker(resource)
|
||||||
return worker.findDocumentHighlights(resource.toString(), fromPosition(position))
|
.then((worker) => {
|
||||||
}).then(entries => {
|
return worker.findDocumentHighlights(
|
||||||
|
resource.toString(),
|
||||||
|
fromPosition(position)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then((entries) => {
|
||||||
if (!entries) {
|
if (!entries) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return entries.map(entry => {
|
return entries.map((entry) => {
|
||||||
return <languages.DocumentHighlight>{
|
return <languages.DocumentHighlight>{
|
||||||
range: toRange(entry.range),
|
range: toRange(entry.range),
|
||||||
kind: toDocumentHighlightKind(entry.kind)
|
kind: toDocumentHighlightKind(entry.kind)
|
||||||
|
|
@ -338,16 +436,23 @@ function toLocation(location: cssService.Location): languages.Location {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DefinitionAdapter {
|
export class DefinitionAdapter {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
public provideDefinition(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
position: Position,
|
||||||
public provideDefinition(model: editor.IReadOnlyModel, position: Position, token: CancellationToken): Promise<languages.Definition> {
|
token: CancellationToken
|
||||||
|
): Promise<languages.Definition> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => {
|
return this._worker(resource)
|
||||||
return worker.findDefinition(resource.toString(), fromPosition(position));
|
.then((worker) => {
|
||||||
}).then(definition => {
|
return worker.findDefinition(
|
||||||
|
resource.toString(),
|
||||||
|
fromPosition(position)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then((definition) => {
|
||||||
if (!definition) {
|
if (!definition) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -359,16 +464,24 @@ export class DefinitionAdapter {
|
||||||
// --- references ------
|
// --- references ------
|
||||||
|
|
||||||
export class ReferenceAdapter implements languages.ReferenceProvider {
|
export class ReferenceAdapter implements languages.ReferenceProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
provideReferences(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
position: Position,
|
||||||
provideReferences(model: editor.IReadOnlyModel, position: Position, context: languages.ReferenceContext, token: CancellationToken): Promise<languages.Location[]> {
|
context: languages.ReferenceContext,
|
||||||
|
token: CancellationToken
|
||||||
|
): Promise<languages.Location[]> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => {
|
return this._worker(resource)
|
||||||
return worker.findReferences(resource.toString(), fromPosition(position));
|
.then((worker) => {
|
||||||
}).then(entries => {
|
return worker.findReferences(
|
||||||
|
resource.toString(),
|
||||||
|
fromPosition(position)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then((entries) => {
|
||||||
if (!entries) {
|
if (!entries) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -379,7 +492,9 @@ export class ReferenceAdapter implements languages.ReferenceProvider {
|
||||||
|
|
||||||
// --- rename ------
|
// --- rename ------
|
||||||
|
|
||||||
function toWorkspaceEdit(edit: cssService.WorkspaceEdit): languages.WorkspaceEdit {
|
function toWorkspaceEdit(
|
||||||
|
edit: cssService.WorkspaceEdit
|
||||||
|
): languages.WorkspaceEdit {
|
||||||
if (!edit || !edit.changes) {
|
if (!edit || !edit.changes) {
|
||||||
return void 0;
|
return void 0;
|
||||||
}
|
}
|
||||||
|
|
@ -399,21 +514,29 @@ function toWorkspaceEdit(edit: cssService.WorkspaceEdit): languages.WorkspaceEdi
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
edits: resourceEdits
|
edits: resourceEdits
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class RenameAdapter implements languages.RenameProvider {
|
export class RenameAdapter implements languages.RenameProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
provideRenameEdits(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
position: Position,
|
||||||
provideRenameEdits(model: editor.IReadOnlyModel, position: Position, newName: string, token: CancellationToken): Promise<languages.WorkspaceEdit> {
|
newName: string,
|
||||||
|
token: CancellationToken
|
||||||
|
): Promise<languages.WorkspaceEdit> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => {
|
return this._worker(resource)
|
||||||
return worker.doRename(resource.toString(), fromPosition(position), newName);
|
.then((worker) => {
|
||||||
}).then(edit => {
|
return worker.doRename(
|
||||||
|
resource.toString(),
|
||||||
|
fromPosition(position),
|
||||||
|
newName
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then((edit) => {
|
||||||
return toWorkspaceEdit(edit);
|
return toWorkspaceEdit(edit);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -425,42 +548,62 @@ function toSymbolKind(kind: cssService.SymbolKind): languages.SymbolKind {
|
||||||
let mKind = languages.SymbolKind;
|
let mKind = languages.SymbolKind;
|
||||||
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case cssService.SymbolKind.File: return mKind.Array;
|
case cssService.SymbolKind.File:
|
||||||
case cssService.SymbolKind.Module: return mKind.Module;
|
return mKind.Array;
|
||||||
case cssService.SymbolKind.Namespace: return mKind.Namespace;
|
case cssService.SymbolKind.Module:
|
||||||
case cssService.SymbolKind.Package: return mKind.Package;
|
return mKind.Module;
|
||||||
case cssService.SymbolKind.Class: return mKind.Class;
|
case cssService.SymbolKind.Namespace:
|
||||||
case cssService.SymbolKind.Method: return mKind.Method;
|
return mKind.Namespace;
|
||||||
case cssService.SymbolKind.Property: return mKind.Property;
|
case cssService.SymbolKind.Package:
|
||||||
case cssService.SymbolKind.Field: return mKind.Field;
|
return mKind.Package;
|
||||||
case cssService.SymbolKind.Constructor: return mKind.Constructor;
|
case cssService.SymbolKind.Class:
|
||||||
case cssService.SymbolKind.Enum: return mKind.Enum;
|
return mKind.Class;
|
||||||
case cssService.SymbolKind.Interface: return mKind.Interface;
|
case cssService.SymbolKind.Method:
|
||||||
case cssService.SymbolKind.Function: return mKind.Function;
|
return mKind.Method;
|
||||||
case cssService.SymbolKind.Variable: return mKind.Variable;
|
case cssService.SymbolKind.Property:
|
||||||
case cssService.SymbolKind.Constant: return mKind.Constant;
|
return mKind.Property;
|
||||||
case cssService.SymbolKind.String: return mKind.String;
|
case cssService.SymbolKind.Field:
|
||||||
case cssService.SymbolKind.Number: return mKind.Number;
|
return mKind.Field;
|
||||||
case cssService.SymbolKind.Boolean: return mKind.Boolean;
|
case cssService.SymbolKind.Constructor:
|
||||||
case cssService.SymbolKind.Array: return mKind.Array;
|
return mKind.Constructor;
|
||||||
|
case cssService.SymbolKind.Enum:
|
||||||
|
return mKind.Enum;
|
||||||
|
case cssService.SymbolKind.Interface:
|
||||||
|
return mKind.Interface;
|
||||||
|
case cssService.SymbolKind.Function:
|
||||||
|
return mKind.Function;
|
||||||
|
case cssService.SymbolKind.Variable:
|
||||||
|
return mKind.Variable;
|
||||||
|
case cssService.SymbolKind.Constant:
|
||||||
|
return mKind.Constant;
|
||||||
|
case cssService.SymbolKind.String:
|
||||||
|
return mKind.String;
|
||||||
|
case cssService.SymbolKind.Number:
|
||||||
|
return mKind.Number;
|
||||||
|
case cssService.SymbolKind.Boolean:
|
||||||
|
return mKind.Boolean;
|
||||||
|
case cssService.SymbolKind.Array:
|
||||||
|
return mKind.Array;
|
||||||
}
|
}
|
||||||
return mKind.Function;
|
return mKind.Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class DocumentSymbolAdapter implements languages.DocumentSymbolProvider {
|
export class DocumentSymbolAdapter implements languages.DocumentSymbolProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
public provideDocumentSymbols(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
token: CancellationToken
|
||||||
public provideDocumentSymbols(model: editor.IReadOnlyModel, token: CancellationToken): Promise<languages.DocumentSymbol[]> {
|
): Promise<languages.DocumentSymbol[]> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => worker.findDocumentSymbols(resource.toString())).then(items => {
|
return this._worker(resource)
|
||||||
|
.then((worker) => worker.findDocumentSymbols(resource.toString()))
|
||||||
|
.then((items) => {
|
||||||
if (!items) {
|
if (!items) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return items.map(item => ({
|
return items.map((item) => ({
|
||||||
name: item.name,
|
name: item.name,
|
||||||
detail: '',
|
detail: '',
|
||||||
containerName: item.containerName,
|
containerName: item.containerName,
|
||||||
|
|
@ -474,40 +617,57 @@ export class DocumentSymbolAdapter implements languages.DocumentSymbolProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DocumentColorAdapter implements languages.DocumentColorProvider {
|
export class DocumentColorAdapter implements languages.DocumentColorProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
public provideDocumentColors(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
token: CancellationToken
|
||||||
public provideDocumentColors(model: editor.IReadOnlyModel, token: CancellationToken): Promise<languages.IColorInformation[]> {
|
): Promise<languages.IColorInformation[]> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => worker.findDocumentColors(resource.toString())).then(infos => {
|
return this._worker(resource)
|
||||||
|
.then((worker) => worker.findDocumentColors(resource.toString()))
|
||||||
|
.then((infos) => {
|
||||||
if (!infos) {
|
if (!infos) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return infos.map(item => ({
|
return infos.map((item) => ({
|
||||||
color: item.color,
|
color: item.color,
|
||||||
range: toRange(item.range)
|
range: toRange(item.range)
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public provideColorPresentations(model: editor.IReadOnlyModel, info: languages.IColorInformation, token: CancellationToken): Promise<languages.IColorPresentation[]> {
|
public provideColorPresentations(
|
||||||
|
model: editor.IReadOnlyModel,
|
||||||
|
info: languages.IColorInformation,
|
||||||
|
token: CancellationToken
|
||||||
|
): Promise<languages.IColorPresentation[]> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range))).then(presentations => {
|
return this._worker(resource)
|
||||||
|
.then((worker) =>
|
||||||
|
worker.getColorPresentations(
|
||||||
|
resource.toString(),
|
||||||
|
info.color,
|
||||||
|
fromRange(info.range)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.then((presentations) => {
|
||||||
if (!presentations) {
|
if (!presentations) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return presentations.map(presentation => {
|
return presentations.map((presentation) => {
|
||||||
let item: languages.IColorPresentation = {
|
let item: languages.IColorPresentation = {
|
||||||
label: presentation.label,
|
label: presentation.label
|
||||||
};
|
};
|
||||||
if (presentation.textEdit) {
|
if (presentation.textEdit) {
|
||||||
item.textEdit = toTextEdit(presentation.textEdit)
|
item.textEdit = toTextEdit(presentation.textEdit);
|
||||||
}
|
}
|
||||||
if (presentation.additionalTextEdits) {
|
if (presentation.additionalTextEdits) {
|
||||||
item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit)
|
item.additionalTextEdits = presentation.additionalTextEdits.map(
|
||||||
|
toTextEdit
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
@ -516,53 +676,72 @@ export class DocumentColorAdapter implements languages.DocumentColorProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
export class FoldingRangeAdapter implements languages.FoldingRangeProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
public provideFoldingRanges(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
context: languages.FoldingContext,
|
||||||
public provideFoldingRanges(model: editor.IReadOnlyModel, context: languages.FoldingContext, token: CancellationToken): Promise<languages.FoldingRange[]> {
|
token: CancellationToken
|
||||||
|
): Promise<languages.FoldingRange[]> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => worker.getFoldingRanges(resource.toString(), context)).then(ranges => {
|
return this._worker(resource)
|
||||||
|
.then((worker) => worker.getFoldingRanges(resource.toString(), context))
|
||||||
|
.then((ranges) => {
|
||||||
if (!ranges) {
|
if (!ranges) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return ranges.map(range => {
|
return ranges.map((range) => {
|
||||||
let result: languages.FoldingRange = {
|
let result: languages.FoldingRange = {
|
||||||
start: range.startLine + 1,
|
start: range.startLine + 1,
|
||||||
end: range.endLine + 1
|
end: range.endLine + 1
|
||||||
};
|
};
|
||||||
if (typeof range.kind !== 'undefined') {
|
if (typeof range.kind !== 'undefined') {
|
||||||
result.kind = toFoldingRangeKind(<cssService.FoldingRangeKind>range.kind);
|
result.kind = toFoldingRangeKind(
|
||||||
|
<cssService.FoldingRangeKind>range.kind
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toFoldingRangeKind(kind: cssService.FoldingRangeKind): languages.FoldingRangeKind {
|
function toFoldingRangeKind(
|
||||||
|
kind: cssService.FoldingRangeKind
|
||||||
|
): languages.FoldingRangeKind {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case cssService.FoldingRangeKind.Comment: return languages.FoldingRangeKind.Comment;
|
case cssService.FoldingRangeKind.Comment:
|
||||||
case cssService.FoldingRangeKind.Imports: return languages.FoldingRangeKind.Imports;
|
return languages.FoldingRangeKind.Comment;
|
||||||
case cssService.FoldingRangeKind.Region: return languages.FoldingRangeKind.Region;
|
case cssService.FoldingRangeKind.Imports:
|
||||||
|
return languages.FoldingRangeKind.Imports;
|
||||||
|
case cssService.FoldingRangeKind.Region:
|
||||||
|
return languages.FoldingRangeKind.Region;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SelectionRangeAdapter implements languages.SelectionRangeProvider {
|
export class SelectionRangeAdapter implements languages.SelectionRangeProvider {
|
||||||
|
constructor(private _worker: WorkerAccessor) {}
|
||||||
|
|
||||||
constructor(private _worker: WorkerAccessor) {
|
public provideSelectionRanges(
|
||||||
}
|
model: editor.IReadOnlyModel,
|
||||||
|
positions: Position[],
|
||||||
public provideSelectionRanges(model: editor.IReadOnlyModel, positions: Position[], token: CancellationToken): Promise<languages.SelectionRange[][]> {
|
token: CancellationToken
|
||||||
|
): Promise<languages.SelectionRange[][]> {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
|
|
||||||
return this._worker(resource).then(worker => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition))).then(selectionRanges => {
|
return this._worker(resource)
|
||||||
|
.then((worker) =>
|
||||||
|
worker.getSelectionRanges(
|
||||||
|
resource.toString(),
|
||||||
|
positions.map(fromPosition)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.then((selectionRanges) => {
|
||||||
if (!selectionRanges) {
|
if (!selectionRanges) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return selectionRanges.map(selectionRange => {
|
return selectionRanges.map((selectionRange) => {
|
||||||
const result: languages.SelectionRange[] = [];
|
const result: languages.SelectionRange[] = [];
|
||||||
while (selectionRange) {
|
while (selectionRange) {
|
||||||
result.push({ range: toRange(selectionRange.range) });
|
result.push({ range: toRange(selectionRange.range) });
|
||||||
|
|
@ -572,5 +751,4 @@ export class SelectionRangeAdapter implements languages.SelectionRangeProvider {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,25 +9,25 @@ 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 {
|
||||||
|
|
@ -85,7 +85,6 @@ export interface ModeConfiguration {
|
||||||
* 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 {
|
||||||
|
|
@ -100,13 +99,16 @@ export interface LanguageServiceDefaults {
|
||||||
// --- CSS configuration and defaults ---------
|
// --- CSS configuration and defaults ---------
|
||||||
|
|
||||||
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
|
|
||||||
private _onDidChange = new Emitter<LanguageServiceDefaults>();
|
private _onDidChange = new Emitter<LanguageServiceDefaults>();
|
||||||
private _diagnosticsOptions: DiagnosticsOptions;
|
private _diagnosticsOptions: DiagnosticsOptions;
|
||||||
private _modeConfiguration: ModeConfiguration;
|
private _modeConfiguration: ModeConfiguration;
|
||||||
private _languageId: string;
|
private _languageId: string;
|
||||||
|
|
||||||
constructor(languageId: string, diagnosticsOptions: DiagnosticsOptions, modeConfiguration: ModeConfiguration) {
|
constructor(
|
||||||
|
languageId: string,
|
||||||
|
diagnosticsOptions: DiagnosticsOptions,
|
||||||
|
modeConfiguration: ModeConfiguration
|
||||||
|
) {
|
||||||
this._languageId = languageId;
|
this._languageId = languageId;
|
||||||
this.setDiagnosticsOptions(diagnosticsOptions);
|
this.setDiagnosticsOptions(diagnosticsOptions);
|
||||||
this.setModeConfiguration(modeConfiguration);
|
this.setModeConfiguration(modeConfiguration);
|
||||||
|
|
@ -136,7 +138,7 @@ class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
setModeConfiguration(modeConfiguration: ModeConfiguration): void {
|
setModeConfiguration(modeConfiguration: ModeConfiguration): void {
|
||||||
this._modeConfiguration = modeConfiguration || Object.create(null);
|
this._modeConfiguration = modeConfiguration || Object.create(null);
|
||||||
this._onDidChange.fire(this);
|
this._onDidChange.fire(this);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const diagnosticDefault: Required<DiagnosticsOptions> = {
|
const diagnosticDefault: Required<DiagnosticsOptions> = {
|
||||||
|
|
@ -161,7 +163,7 @@ const diagnosticDefault: Required<DiagnosticsOptions> = {
|
||||||
float: 'ignore',
|
float: 'ignore',
|
||||||
idSelector: 'ignore'
|
idSelector: 'ignore'
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const modeConfigurationDefault: Required<ModeConfiguration> = {
|
const modeConfigurationDefault: Required<ModeConfiguration> = {
|
||||||
completionItems: true,
|
completionItems: true,
|
||||||
|
|
@ -175,11 +177,23 @@ const modeConfigurationDefault: Required<ModeConfiguration> = {
|
||||||
foldingRanges: true,
|
foldingRanges: true,
|
||||||
diagnostics: true,
|
diagnostics: true,
|
||||||
selectionRanges: true
|
selectionRanges: true
|
||||||
}
|
};
|
||||||
|
|
||||||
export const cssDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl('css', diagnosticDefault, modeConfigurationDefault);
|
export const cssDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl(
|
||||||
export const scssDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl('scss', diagnosticDefault, modeConfigurationDefault);
|
'css',
|
||||||
export const lessDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl('less', diagnosticDefault, modeConfigurationDefault);
|
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
|
// export to the global based API
|
||||||
(<any>languages).json = { cssDefaults, lessDefaults, scssDefaults };
|
(<any>languages).json = { cssDefaults, lessDefaults, scssDefaults };
|
||||||
|
|
@ -191,13 +205,13 @@ function getMode(): Promise<typeof mode> {
|
||||||
}
|
}
|
||||||
|
|
||||||
languages.onLanguage('less', () => {
|
languages.onLanguage('less', () => {
|
||||||
getMode().then(mode => mode.setupMode(lessDefaults));
|
getMode().then((mode) => mode.setupMode(lessDefaults));
|
||||||
});
|
});
|
||||||
|
|
||||||
languages.onLanguage('scss', () => {
|
languages.onLanguage('scss', () => {
|
||||||
getMode().then(mode => mode.setupMode(scssDefaults));
|
getMode().then((mode) => mode.setupMode(scssDefaults));
|
||||||
});
|
});
|
||||||
|
|
||||||
languages.onLanguage('css', () => {
|
languages.onLanguage('css', () => {
|
||||||
getMode().then(mode => mode.setupMode(cssDefaults));
|
getMode().then((mode) => mode.setupMode(cssDefaults));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ 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;
|
||||||
|
|
@ -22,9 +21,14 @@ export class WorkerManager {
|
||||||
constructor(defaults: LanguageServiceDefaults) {
|
constructor(defaults: LanguageServiceDefaults) {
|
||||||
this._defaults = defaults;
|
this._defaults = defaults;
|
||||||
this._worker = null;
|
this._worker = null;
|
||||||
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1000);
|
this._idleCheckInterval = window.setInterval(
|
||||||
|
() => this._checkIfIdle(),
|
||||||
|
30 * 1000
|
||||||
|
);
|
||||||
this._lastUsedTime = 0;
|
this._lastUsedTime = 0;
|
||||||
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
this._configChangeListener = this._defaults.onDidChange(() =>
|
||||||
|
this._stopWorker()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _stopWorker(): void {
|
private _stopWorker(): void {
|
||||||
|
|
@ -56,7 +60,6 @@ export class WorkerManager {
|
||||||
|
|
||||||
if (!this._client) {
|
if (!this._client) {
|
||||||
this._worker = editor.createWebWorker<CSSWorker>({
|
this._worker = editor.createWebWorker<CSSWorker>({
|
||||||
|
|
||||||
// module that exports the create() method and returns a `CSSWorker` instance
|
// module that exports the create() method and returns a `CSSWorker` instance
|
||||||
moduleId: 'vs/language/css/cssWorker',
|
moduleId: 'vs/language/css/cssWorker',
|
||||||
|
|
||||||
|
|
@ -69,7 +72,7 @@ export class WorkerManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this._client = <Promise<CSSWorker>><any>this._worker.getProxy();
|
this._client = <Promise<CSSWorker>>(<any>this._worker.getProxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._client;
|
return this._client;
|
||||||
|
|
@ -77,10 +80,13 @@ export class WorkerManager {
|
||||||
|
|
||||||
getLanguageServiceWorker(...resources: Uri[]): Promise<CSSWorker> {
|
getLanguageServiceWorker(...resources: Uri[]): Promise<CSSWorker> {
|
||||||
let _client: CSSWorker;
|
let _client: CSSWorker;
|
||||||
return this._getClient().then((client) => {
|
return this._getClient()
|
||||||
_client = client
|
.then((client) => {
|
||||||
}).then(_ => {
|
_client = client;
|
||||||
return this._worker.withSyncedResources(resources)
|
})
|
||||||
}).then(_ => _client);
|
.then((_) => {
|
||||||
|
return this._worker.withSyncedResources(resources);
|
||||||
|
})
|
||||||
|
.then((_) => _client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,28 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||||
<link rel="stylesheet" data-name="vs/editor/editor.main" href="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.css">
|
<link
|
||||||
</head>
|
rel="stylesheet"
|
||||||
<body>
|
data-name="vs/editor/editor.main"
|
||||||
|
href="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.css"
|
||||||
|
/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Monaco Editor CSS test page</h2>
|
||||||
|
<div
|
||||||
|
id="container"
|
||||||
|
style="width: 800px; height: 600px; border: 1px solid grey"
|
||||||
|
></div>
|
||||||
|
|
||||||
<h2>Monaco Editor CSS test page</h2>
|
<script>
|
||||||
<div id="container" style="width:800px;height:600px;border:1px solid grey"></div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// Loading basic-languages to get the css language definition
|
// Loading basic-languages to get the css language definition
|
||||||
var paths = {
|
var paths = {
|
||||||
'vs/basic-languages': '../node_modules/monaco-languages/release/dev',
|
'vs/basic-languages': '../node_modules/monaco-languages/release/dev',
|
||||||
'vs/language/css': '../release/dev',
|
'vs/language/css': '../release/dev',
|
||||||
'vs': '../node_modules/monaco-editor-core/dev/vs'
|
vs: '../node_modules/monaco-editor-core/dev/vs'
|
||||||
}
|
};
|
||||||
if (document.location.protocol === 'http:') {
|
if (document.location.protocol === 'http:') {
|
||||||
// Add support for running local http server
|
// Add support for running local http server
|
||||||
let testIndex = document.location.pathname.indexOf('/test/');
|
let testIndex = document.location.pathname.indexOf('/test/');
|
||||||
|
|
@ -28,17 +34,19 @@
|
||||||
var require = {
|
var require = {
|
||||||
paths: paths
|
paths: paths
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<script src="../node_modules/monaco-editor-core/dev/vs/loader.js"></script>
|
<script src="../node_modules/monaco-editor-core/dev/vs/loader.js"></script>
|
||||||
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.nls.js"></script>
|
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.nls.js"></script>
|
||||||
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script>
|
<script src="../node_modules/monaco-editor-core/dev/vs/editor/editor.main.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
require([
|
require([
|
||||||
'vs/basic-languages/monaco.contribution',
|
'vs/basic-languages/monaco.contribution',
|
||||||
'vs/language/css/monaco.contribution'
|
'vs/language/css/monaco.contribution'
|
||||||
], function() {
|
], function () {
|
||||||
var editor = monaco.editor.create(document.getElementById('container'), {
|
var editor = monaco.editor.create(
|
||||||
|
document.getElementById('container'),
|
||||||
|
{
|
||||||
value: [
|
value: [
|
||||||
'html {',
|
'html {',
|
||||||
' background-color: #e2e2e2;',
|
' background-color: #e2e2e2;',
|
||||||
|
|
@ -158,7 +166,7 @@
|
||||||
' margin-right: 20px;',
|
' margin-right: 20px;',
|
||||||
' margin-bottom: 20px;',
|
' margin-bottom: 20px;',
|
||||||
' margin-top: 20px;',
|
' margin-top: 20px;',
|
||||||
' background-image: url(\'../Images/documents.png\');',
|
" background-image: url('../Images/documents.png');",
|
||||||
' background-repeat: no-repeat;',
|
' background-repeat: no-repeat;',
|
||||||
'}',
|
'}',
|
||||||
'',
|
'',
|
||||||
|
|
@ -220,7 +228,7 @@
|
||||||
' border: solid #8ABAE4;',
|
' border: solid #8ABAE4;',
|
||||||
' padding-top: 0px;',
|
' padding-top: 0px;',
|
||||||
' padding-left: 0px;',
|
' padding-left: 0px;',
|
||||||
' background-image: url(\'../Images/documents.png\');',
|
" background-image: url('../Images/documents.png');",
|
||||||
' background-color: #EFEFEF;',
|
' background-color: #EFEFEF;',
|
||||||
' }',
|
' }',
|
||||||
'',
|
'',
|
||||||
|
|
@ -864,12 +872,12 @@
|
||||||
'',
|
'',
|
||||||
'.monaco-editor.monaco .monaco-editor-background, .monaco-editor.vs .monaco-editor-background, .monaco-editor.eclipse .monaco-editor-background {',
|
'.monaco-editor.monaco .monaco-editor-background, .monaco-editor.vs .monaco-editor-background, .monaco-editor.eclipse .monaco-editor-background {',
|
||||||
' background: #F9F9F9;',
|
' background: #F9F9F9;',
|
||||||
'}',
|
'}'
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
language: 'css'
|
language: 'css'
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
</script>
|
||||||
</script>
|
</body>
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue