mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Ship ESM; Adopt latest deps
This commit is contained in:
parent
13c997af18
commit
ca775cc8f3
15 changed files with 8826 additions and 217 deletions
|
|
@ -1,8 +1,10 @@
|
|||
/.vscode/
|
||||
/lib/
|
||||
/out/
|
||||
/scripts/
|
||||
/src/
|
||||
/test/
|
||||
/release/dev/
|
||||
/gulpfile.js
|
||||
/.gitignore
|
||||
/.npmignore
|
||||
/package-lock.json
|
||||
/webpack.dev.config.js
|
||||
/webpack.min.config.js
|
||||
|
|
|
|||
187
gulpfile.js
187
gulpfile.js
|
|
@ -1,187 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
var gulp = require('gulp');
|
||||
var tsb = require('gulp-tsb');
|
||||
var assign = require('object-assign');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var merge = require('merge-stream');
|
||||
var rjs = require('gulp-requirejs');
|
||||
var uglify = require('gulp-uglify');
|
||||
var rimraf = require('rimraf');
|
||||
var es = require('event-stream');
|
||||
|
||||
gulp.task('clean-release', function(cb) { rimraf('release', { maxBusyTries: 1 }, cb); });
|
||||
gulp.task('release', ['clean-release','compile'], function() {
|
||||
|
||||
var sha1 = getGitVersion(__dirname);
|
||||
var semver = require('./package.json').version;
|
||||
var headerVersion = semver + '(' + sha1 + ')';
|
||||
|
||||
var BUNDLED_FILE_HEADER = [
|
||||
'/*!-----------------------------------------------------------------------------',
|
||||
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
||||
' * monaco-html version: ' + headerVersion,
|
||||
' * Released under the MIT license',
|
||||
' * https://github.com/Microsoft/monaco-html/blob/master/LICENSE.md',
|
||||
' *-----------------------------------------------------------------------------*/',
|
||||
''
|
||||
].join('\n');
|
||||
|
||||
function getDependencyLocation(name, libLocation, container) {
|
||||
var location = __dirname + '/node_modules/' + name + '/' + libLocation;
|
||||
if (!fs.existsSync(location)) {
|
||||
var oldLocation = __dirname + '/node_modules/' + container + '/node_modules/' + name + '/' + libLocation;
|
||||
if (!fs.existsSync(oldLocation)) {
|
||||
console.error('Unable to find ' + name + ' node module at ' + location + ' or ' + oldLocation);
|
||||
return;
|
||||
}
|
||||
return oldLocation;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
var uriLocation = getDependencyLocation('vscode-uri', 'lib', 'vscode-html-languageservice');
|
||||
|
||||
function bundleOne(moduleId, exclude) {
|
||||
|
||||
|
||||
return rjs({
|
||||
baseUrl: '/out/',
|
||||
name: 'vs/language/html/' + moduleId,
|
||||
out: moduleId + '.js',
|
||||
exclude: exclude,
|
||||
paths: {
|
||||
'vs/language/html': __dirname + '/out'
|
||||
},
|
||||
packages: [{
|
||||
name: 'vscode-html-languageservice/lib/parser/htmlScanner',
|
||||
location: __dirname + '/node_modules/vscode-html-languageservice/lib/parser',
|
||||
main: 'htmlScanner'
|
||||
}, {
|
||||
name: 'vscode-html-languageservice',
|
||||
location: __dirname + '/node_modules/vscode-html-languageservice/lib',
|
||||
main: 'htmlLanguageService'
|
||||
}, {
|
||||
name: 'vscode-languageserver-types',
|
||||
location: __dirname + '/node_modules/vscode-languageserver-types/lib',
|
||||
main: 'main'
|
||||
}, {
|
||||
name: 'vscode-uri',
|
||||
location: uriLocation,
|
||||
main: 'index'
|
||||
}, {
|
||||
name: 'vscode-nls',
|
||||
location: __dirname + '/out/fillers',
|
||||
main: 'vscode-nls'
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
return merge(
|
||||
merge(
|
||||
bundleOne('monaco.contribution', ['vs/language/html/htmlMode']),
|
||||
bundleOne('htmlMode'),
|
||||
bundleOne('htmlWorker')
|
||||
)
|
||||
.pipe(es.through(function(data) {
|
||||
data.contents = new Buffer(
|
||||
BUNDLED_FILE_HEADER
|
||||
+ data.contents.toString()
|
||||
);
|
||||
this.emit('data', data);
|
||||
}))
|
||||
.pipe(gulp.dest('./release/dev'))
|
||||
.pipe(uglify({
|
||||
preserveComments: function(node, token) {
|
||||
var text = token.value;
|
||||
if (text.indexOf('monaco-html version') >= 0) {
|
||||
// this is the main copyright header
|
||||
return true;
|
||||
}
|
||||
if (text.indexOf('Copyright (c) Microsoft') >= 0) {
|
||||
// this is another Microsoft copyright header (not the main)
|
||||
return false;
|
||||
}
|
||||
if (/copyright/i.test(text)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}))
|
||||
.pipe(gulp.dest('./release/min')),
|
||||
gulp.src('src/monaco.d.ts').pipe(gulp.dest('./release/min'))
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
var compilation = tsb.create(assign({ verbose: true }, require('./src/tsconfig.json').compilerOptions));
|
||||
|
||||
var tsSources = 'src/**/*.ts';
|
||||
|
||||
function compileTask() {
|
||||
return merge(
|
||||
gulp.src(tsSources).pipe(compilation())
|
||||
)
|
||||
.pipe(gulp.dest('out'));
|
||||
}
|
||||
|
||||
gulp.task('clean-out', function(cb) { rimraf('out', { maxBusyTries: 1 }, cb); });
|
||||
gulp.task('compile', ['clean-out'], compileTask);
|
||||
gulp.task('compile-without-clean', compileTask);
|
||||
gulp.task('watch', ['compile'], function() {
|
||||
gulp.watch(tsSources, ['compile-without-clean']);
|
||||
});
|
||||
|
||||
function getGitVersion(repo) {
|
||||
var git = path.join(repo, '.git');
|
||||
var headPath = path.join(git, 'HEAD');
|
||||
var head;
|
||||
|
||||
try {
|
||||
head = fs.readFileSync(headPath, 'utf8').trim();
|
||||
} catch (e) {
|
||||
return void 0;
|
||||
}
|
||||
|
||||
if (/^[0-9a-f]{40}$/i.test(head)) {
|
||||
return head;
|
||||
}
|
||||
|
||||
var refMatch = /^ref: (.*)$/.exec(head);
|
||||
|
||||
if (!refMatch) {
|
||||
return void 0;
|
||||
}
|
||||
|
||||
var ref = refMatch[1];
|
||||
var refPath = path.join(git, ref);
|
||||
|
||||
try {
|
||||
return fs.readFileSync(refPath, 'utf8').trim();
|
||||
} catch (e) {
|
||||
// noop
|
||||
}
|
||||
|
||||
var packedRefsPath = path.join(git, 'packed-refs');
|
||||
var refsRaw;
|
||||
|
||||
try {
|
||||
refsRaw = fs.readFileSync(packedRefsPath, 'utf8').trim();
|
||||
} catch (e) {
|
||||
return void 0;
|
||||
}
|
||||
|
||||
var refsRegex = /^([0-9a-f]{40})\s+(.+)$/gm;
|
||||
var refsMatch;
|
||||
var refs = {};
|
||||
|
||||
while (refsMatch = refsRegex.exec(refsRaw)) {
|
||||
refs[refsMatch[2]] = refsMatch[1];
|
||||
}
|
||||
|
||||
return refs[ref];
|
||||
}
|
||||
8488
package-lock.json
generated
Normal file
8488
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
26
package.json
26
package.json
|
|
@ -3,9 +3,9 @@
|
|||
"version": "1.3.2",
|
||||
"description": "HTML plugin for the Monaco Editor",
|
||||
"scripts": {
|
||||
"compile": "gulp compile",
|
||||
"watch": "gulp watch",
|
||||
"prepublish": "gulp release",
|
||||
"compile": "node ./scripts/rmdir ./out && tsc -p ./src",
|
||||
"watch": "tsc -p ./src --watch",
|
||||
"prepublish": "node ./scripts/rmdir ./release && npm run compile && node ./scripts/release.js && webpack --config webpack.dev.config.js && webpack --config webpack.min.config.js && node ./scripts/copy ./src/monaco.d.ts ./release/monaco.d.ts",
|
||||
"install-service-next": "npm install vscode-html-languageservice@next -f -D && npm install vscode-languageserver-types@next -f -D",
|
||||
"install-service-local": "npm install ../vscode-html-languageservice -f -D && npm install ../vscode-languageserver-node/types -f -D"
|
||||
},
|
||||
|
|
@ -19,19 +19,13 @@
|
|||
"url": "https://github.com/Microsoft/monaco-editor/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"event-stream": "^3.3.2",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-requirejs": "^0.1.3",
|
||||
"gulp-tsb": "^2.0.0",
|
||||
"gulp-uglify": "^1.5.3",
|
||||
"merge-stream": "^1.0.0",
|
||||
"monaco-editor-core": "^0.10.0",
|
||||
"monaco-editor-core": "0.11.1",
|
||||
"monaco-languages": "^0.9.0",
|
||||
"monaco-typescript": "^2.1.2",
|
||||
"object-assign": "^4.1.0",
|
||||
"rimraf": "^2.5.2",
|
||||
"typescript": "^2.3.4",
|
||||
"vscode-html-languageservice": "^2.0.4",
|
||||
"vscode-languageserver-types": "^3.2.0"
|
||||
"monaco-typescript": "^2.3.0",
|
||||
"typescript": "^2.7.2",
|
||||
"vscode-html-languageservice": "^2.1.1",
|
||||
"vscode-languageserver-types": "^3.6.1",
|
||||
"webpack": "^4.1.1",
|
||||
"webpack-cli": "^2.0.10"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
scripts/copy.js
Normal file
30
scripts/copy.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const source = path.join(process.cwd(), process.argv[2]);
|
||||
const destination = path.join(process.cwd(), process.argv[3]);
|
||||
|
||||
// ensure target dir
|
||||
(function () {
|
||||
let dirs = [];
|
||||
let dirname = path.dirname(destination);
|
||||
while (dirname !== process.cwd()) {
|
||||
dirs.push(dirname);
|
||||
dirname = path.dirname(dirname);
|
||||
}
|
||||
|
||||
dirs.reverse();
|
||||
|
||||
dirs.forEach((dir) => {
|
||||
try { fs.mkdirSync(dir); } catch (err) { }
|
||||
})
|
||||
})();
|
||||
|
||||
fs.writeFileSync(destination, fs.readFileSync(source));
|
||||
|
||||
console.log(`Copied ${process.argv[2]} to ${process.argv[3]}`);
|
||||
178
scripts/release.js
Normal file
178
scripts/release.js
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
exports.__esModule = true;
|
||||
var fs = require("fs");
|
||||
var ts = require("typescript");
|
||||
var path = require("path");
|
||||
var REPO_ROOT = path.join(__dirname, '../');
|
||||
process({
|
||||
repoRoot: REPO_ROOT,
|
||||
esmSource: 'out',
|
||||
esmDestination: 'release/esm',
|
||||
entryPoints: [
|
||||
'monaco.contribution.js',
|
||||
'htmlMode.js',
|
||||
'html.worker.js',
|
||||
'../node_modules/vscode-html-languageservice/lib/esm/beautify/beautify-css.js',
|
||||
'../node_modules/vscode-html-languageservice/lib/esm/beautify/beautify.js',
|
||||
],
|
||||
resolveAlias: {
|
||||
'vscode-nls': path.join(REPO_ROOT, "out/fillers/vscode-nls.js")
|
||||
},
|
||||
resolveSkip: [
|
||||
'monaco-editor-core'
|
||||
],
|
||||
destinationFolderSimplification: {
|
||||
'node_modules': '_deps',
|
||||
'vscode-languageserver-types/lib/esm': 'vscode-languageserver-types',
|
||||
'vscode-uri/lib/esm': 'vscode-uri',
|
||||
'vscode-html-languageservice/lib/esm': 'vscode-html-languageservice'
|
||||
}
|
||||
});
|
||||
function process(options) {
|
||||
options.repoRoot = path.normalize(options.repoRoot).replace(/(\/|\\)$/, '');
|
||||
var ESM_SRC = path.join(options.repoRoot, options.esmSource);
|
||||
var ESM_DEST = path.join(options.repoRoot, options.esmDestination);
|
||||
var in_queue = Object.create(null);
|
||||
var queue = [];
|
||||
var enqueue = function (filePath) {
|
||||
if (in_queue[filePath]) {
|
||||
return;
|
||||
}
|
||||
in_queue[filePath] = true;
|
||||
queue.push(filePath);
|
||||
};
|
||||
var seenDir = {};
|
||||
var createDirectoryRecursive = function (dir) {
|
||||
if (seenDir[dir]) {
|
||||
return;
|
||||
}
|
||||
var lastSlash = dir.lastIndexOf('/');
|
||||
if (lastSlash === -1) {
|
||||
lastSlash = dir.lastIndexOf('\\');
|
||||
}
|
||||
if (lastSlash !== -1) {
|
||||
createDirectoryRecursive(dir.substring(0, lastSlash));
|
||||
}
|
||||
seenDir[dir] = true;
|
||||
try {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
catch (err) { }
|
||||
};
|
||||
seenDir[options.repoRoot] = true;
|
||||
var applyDestinationFolderSimplifications = function (filePath) {
|
||||
filePath = filePath.replace(/\\/g, '/');
|
||||
for (var key in options.destinationFolderSimplification) {
|
||||
var test = key.replace(/\\/g, '/');
|
||||
while (filePath.indexOf(test) >= 0) {
|
||||
filePath = filePath.replace(test, options.destinationFolderSimplification[test]);
|
||||
}
|
||||
}
|
||||
return filePath;
|
||||
};
|
||||
var shouldSkipImport = function (importText) {
|
||||
for (var i = 0; i < options.resolveSkip.length; i++) {
|
||||
var skip = options.resolveSkip[i];
|
||||
if (importText.indexOf(skip) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
var computeDestinationFilePath = function (filePath) {
|
||||
if (filePath.indexOf(ESM_SRC) === 0) {
|
||||
// This file is from our sources
|
||||
return path.join(ESM_DEST, path.relative(ESM_SRC, filePath));
|
||||
}
|
||||
else {
|
||||
// This file is from node_modules
|
||||
return path.normalize(applyDestinationFolderSimplifications(path.join(ESM_DEST, path.relative(options.repoRoot, filePath))));
|
||||
}
|
||||
};
|
||||
var write = function (filePath, fileContents) {
|
||||
var finalFilePath = computeDestinationFilePath(filePath);
|
||||
createDirectoryRecursive(path.dirname(finalFilePath));
|
||||
fs.writeFileSync(finalFilePath, fileContents);
|
||||
};
|
||||
options.entryPoints.forEach(function (filePath) {
|
||||
enqueue(path.join(ESM_SRC, filePath));
|
||||
});
|
||||
while (queue.length > 0) {
|
||||
var filePath = queue.shift();
|
||||
var fileContents = fs.readFileSync(filePath).toString();
|
||||
var info = ts.preProcessFile(fileContents);
|
||||
for (var i = info.importedFiles.length - 1; i >= 0; i--) {
|
||||
var importText = info.importedFiles[i].fileName;
|
||||
if (shouldSkipImport(importText)) {
|
||||
continue;
|
||||
}
|
||||
var pos = info.importedFiles[i].pos;
|
||||
var end = info.importedFiles[i].end;
|
||||
if (/(^\.\/)|(^\.\.\/)/.test(importText)) {
|
||||
// Relative import
|
||||
var importedFilename = path.join(path.dirname(filePath), importText) + '.js';
|
||||
enqueue(importedFilename);
|
||||
}
|
||||
else {
|
||||
var importedFilename = void 0;
|
||||
if (options.resolveAlias[importText]) {
|
||||
importedFilename = options.resolveAlias[importText];
|
||||
}
|
||||
else {
|
||||
importedFilename = findNodeModuleImport(options.repoRoot, importText, filePath);
|
||||
}
|
||||
var myDestinationPath = computeDestinationFilePath(filePath);
|
||||
var importDestinationPath = computeDestinationFilePath(importedFilename);
|
||||
var relativePath = path.relative(path.dirname(myDestinationPath), importDestinationPath);
|
||||
if (!/(^\.\/)|(^\.\.\/)/.test(relativePath)) {
|
||||
relativePath = './' + relativePath;
|
||||
}
|
||||
relativePath = relativePath.replace(/\\/g, '/');
|
||||
relativePath = relativePath.replace(/\.js$/, '');
|
||||
fileContents = (fileContents.substring(0, pos + 1)
|
||||
+ relativePath
|
||||
+ fileContents.substring(end + 1));
|
||||
enqueue(importedFilename);
|
||||
}
|
||||
}
|
||||
write(filePath, fileContents);
|
||||
}
|
||||
}
|
||||
function findNodeModuleImport(repoRoot, module, sourceFilePath) {
|
||||
var modulePath = findNodeModule(repoRoot, module, sourceFilePath);
|
||||
var modulePackagePath = path.join(modulePath, 'package.json');
|
||||
if (!fs.existsSync(modulePackagePath)) {
|
||||
throw new Error("Missing " + modulePackagePath + " in node module " + modulePath);
|
||||
}
|
||||
var modulePackage = JSON.parse(fs.readFileSync(modulePackagePath).toString());
|
||||
if (typeof modulePackage.module !== 'string') {
|
||||
throw new Error("Missing property 'module' package.json at " + modulePackagePath);
|
||||
}
|
||||
var result = path.join(modulePath, modulePackage.module);
|
||||
if (!fs.existsSync(result)) {
|
||||
throw new Error("Missing file " + result);
|
||||
}
|
||||
return result;
|
||||
function findNodeModule(repoRoot, module, sourceFilePath) {
|
||||
var modulePaths = generatePaths(repoRoot, module, sourceFilePath);
|
||||
for (var i = 0; i < modulePaths.length; i++) {
|
||||
if (fs.existsSync(modulePaths[i])) {
|
||||
return modulePaths[i];
|
||||
}
|
||||
}
|
||||
throw new Error("Cannot find module " + module + " requested by " + sourceFilePath);
|
||||
}
|
||||
function generatePaths(repoRoot, module, sourceFilePath) {
|
||||
var sourceDir = path.dirname(sourceFilePath);
|
||||
var result = [];
|
||||
while (sourceDir.length >= repoRoot.length) {
|
||||
result.push(path.join(sourceDir, 'node_modules', module));
|
||||
sourceDir = path.dirname(sourceDir);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
28
scripts/rmdir.js
Normal file
28
scripts/rmdir.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const target = path.join(process.cwd(), process.argv[2]);
|
||||
if (fs.existsSync(target)) {
|
||||
rmDir(target);
|
||||
}
|
||||
console.log(`Deleted ${process.argv[2]}`);
|
||||
|
||||
function rmDir(dirPath) {
|
||||
let entries = fs.readdirSync(dirPath);
|
||||
if (entries.length > 0) {
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var filePath = path.join(dirPath, entries[i]);
|
||||
if (fs.statSync(filePath).isFile()) {
|
||||
fs.unlinkSync(filePath);
|
||||
} else {
|
||||
rmDir(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
fs.rmdirSync(dirPath);
|
||||
}
|
||||
28
scripts/webpack.js
Normal file
28
scripts/webpack.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '..');
|
||||
|
||||
exports.createWebpackConfig = function (isDev) {
|
||||
let targetFolder = isDev ? './release/dev' : './release/min';
|
||||
let mode = isDev ? 'development' : 'production';
|
||||
|
||||
return {
|
||||
entry: {
|
||||
"monaco.contribution": './release/esm/monaco.contribution',
|
||||
"htmlMode": './release/esm/htmlMode',
|
||||
"htmlWorker": './release/esm/htmlWorker'
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: path.resolve(REPO_ROOT, targetFolder),
|
||||
libraryTarget: "amd"
|
||||
},
|
||||
mode: mode,
|
||||
plugins: [
|
||||
new webpack.optimize.LimitChunkCountPlugin({
|
||||
maxChunks: 1,
|
||||
})
|
||||
],
|
||||
};
|
||||
};
|
||||
15
src/html.worker.ts
Normal file
15
src/html.worker.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker';
|
||||
import { HTMLWorker } from './htmlWorker';
|
||||
|
||||
self.onmessage = () => {
|
||||
// ignore the first message
|
||||
worker.initialize((ctx, createData) => {
|
||||
return new HTMLWorker(ctx, createData)
|
||||
});
|
||||
};
|
||||
|
|
@ -41,13 +41,13 @@ export class HTMLWorker {
|
|||
let textEdits = this._languageService.format(document, range, this._languageSettings && this._languageSettings.format);
|
||||
return Promise.as(textEdits);
|
||||
}
|
||||
findDocumentHighlights(uri: string, position: ls.Position): Promise<ls.DocumentHighlight[]> {
|
||||
findDocumentHighlights(uri: string, position: ls.Position): Thenable<ls.DocumentHighlight[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let htmlDocument = this._languageService.parseHTMLDocument(document);
|
||||
let highlights = this._languageService.findDocumentHighlights(document, position, htmlDocument);
|
||||
return Promise.as(highlights);
|
||||
}
|
||||
findDocumentLinks(uri: string): Promise<ls.DocumentLink[]> {
|
||||
findDocumentLinks(uri: string): Thenable<ls.DocumentLink[]> {
|
||||
let document = this._getTextDocument(uri);
|
||||
let links = this._languageService.findDocumentLinks(document, null);
|
||||
return Promise.as(links);
|
||||
|
|
|
|||
|
|
@ -222,12 +222,19 @@ function toCompletionItem(entry: ls.CompletionItem): DataCompletionItem {
|
|||
};
|
||||
}
|
||||
|
||||
function fromMarkdownString(entry: string | monaco.IMarkdownString): ls.MarkupContent {
|
||||
return {
|
||||
kind: (typeof entry === 'string' ? ls.MarkupKind.PlainText : ls.MarkupKind.PlainText),
|
||||
value: (typeof entry === 'string' ? entry : entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
function fromCompletionItem(entry: DataCompletionItem): ls.CompletionItem {
|
||||
let item : ls.CompletionItem = {
|
||||
label: entry.label,
|
||||
sortText: entry.sortText,
|
||||
filterText: entry.filterText,
|
||||
documentation: entry.documentation,
|
||||
documentation: fromMarkdownString(entry.documentation),
|
||||
detail: entry.detail,
|
||||
kind: fromCompletionItemKind(entry.kind),
|
||||
data: entry.data
|
||||
|
|
@ -292,14 +299,38 @@ export class CompletionAdapter implements monaco.languages.CompletionItemProvide
|
|||
}
|
||||
}
|
||||
|
||||
function toMarkedStringArray(contents: ls.MarkedString | ls.MarkedString[]): monaco.MarkedString[] {
|
||||
function isMarkupContent(thing: any): thing is ls.MarkupContent {
|
||||
return thing && typeof thing === 'object' && typeof (<ls.MarkupContent>thing).kind === 'string';
|
||||
}
|
||||
|
||||
function toMarkdownString(entry: ls.MarkupContent | ls.MarkedString): monaco.IMarkdownString {
|
||||
if (typeof entry === 'string') {
|
||||
return {
|
||||
value: entry
|
||||
};
|
||||
}
|
||||
if (isMarkupContent(entry)) {
|
||||
if (entry.kind === 'plaintext') {
|
||||
return {
|
||||
value: entry.value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
|
||||
};
|
||||
}
|
||||
return {
|
||||
value: entry.value
|
||||
};
|
||||
}
|
||||
|
||||
return { value: '```' + entry.value + '\n' + entry.value + '\n```\n' };
|
||||
}
|
||||
|
||||
function toMarkedStringArray(contents: ls.MarkedString | ls.MarkedString[]): monaco.IMarkdownString[] {
|
||||
if (!contents) {
|
||||
return void 0;
|
||||
}
|
||||
if (Array.isArray(contents)) {
|
||||
return (<ls.MarkedString[]>contents);
|
||||
return contents.map(toMarkdownString);
|
||||
}
|
||||
return [<ls.MarkedString>contents];
|
||||
return [toMarkdownString(contents)];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ monaco.languages.html = createAPI();
|
|||
// --- Registration to monaco editor ---
|
||||
|
||||
function withMode(callback: (module: typeof mode) => void): void {
|
||||
require<typeof mode>(['vs/language/html/htmlMode'], callback);
|
||||
require<typeof mode>(['./htmlMode'], callback);
|
||||
}
|
||||
|
||||
monaco.languages.onLanguage(htmlLanguageId, () => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "umd",
|
||||
"module": "es6",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../out",
|
||||
"target": "es5"
|
||||
|
|
|
|||
1
webpack.dev.config.js
Normal file
1
webpack.dev.config.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
module.exports = require('./scripts/webpack').createWebpackConfig(true);
|
||||
1
webpack.min.config.js
Normal file
1
webpack.min.config.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
module.exports = require('./scripts/webpack').createWebpackConfig(false);
|
||||
Loading…
Add table
Add a link
Reference in a new issue