mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 18:32:56 +01:00
Increase printWidth
This commit is contained in:
parent
233f97cde9
commit
c196027bdc
13 changed files with 109 additions and 337 deletions
|
|
@ -3,5 +3,6 @@
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"semi": true,
|
"semi": true,
|
||||||
"useTabs": true
|
"useTabs": true,
|
||||||
|
"printWidth": 100
|
||||||
}
|
}
|
||||||
|
|
|
||||||
39
monaco.d.ts
vendored
39
monaco.d.ts
vendored
|
|
@ -285,10 +285,7 @@ declare namespace monaco.languages.typescript {
|
||||||
* Get code completions for the given file and position.
|
* Get code completions for the given file and position.
|
||||||
* @returns `Promise<typescript.CompletionInfo | undefined>`
|
* @returns `Promise<typescript.CompletionInfo | undefined>`
|
||||||
*/
|
*/
|
||||||
getCompletionsAtPosition(
|
getCompletionsAtPosition(fileName: string, position: number): Promise<any | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any | undefined>;
|
|
||||||
/**
|
/**
|
||||||
* Get code completion details for the given file, position, and entry.
|
* Get code completion details for the given file, position, and entry.
|
||||||
* @returns `Promise<typescript.CompletionEntryDetails | undefined>`
|
* @returns `Promise<typescript.CompletionEntryDetails | undefined>`
|
||||||
|
|
@ -302,18 +299,12 @@ declare namespace monaco.languages.typescript {
|
||||||
* Get signature help items for the item at the given file and position.
|
* Get signature help items for the item at the given file and position.
|
||||||
* @returns `Promise<typescript.SignatureHelpItems | undefined>`
|
* @returns `Promise<typescript.SignatureHelpItems | undefined>`
|
||||||
*/
|
*/
|
||||||
getSignatureHelpItems(
|
getSignatureHelpItems(fileName: string, position: number): Promise<any | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any | undefined>;
|
|
||||||
/**
|
/**
|
||||||
* Get quick info for the item at the given position in the file.
|
* Get quick info for the item at the given position in the file.
|
||||||
* @returns `Promise<typescript.QuickInfo | undefined>`
|
* @returns `Promise<typescript.QuickInfo | undefined>`
|
||||||
*/
|
*/
|
||||||
getQuickInfoAtPosition(
|
getQuickInfoAtPosition(fileName: string, position: number): Promise<any | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any | undefined>;
|
|
||||||
/**
|
/**
|
||||||
* Get other ranges which are related to the item at the given position in the file (often used for highlighting).
|
* Get other ranges which are related to the item at the given position in the file (often used for highlighting).
|
||||||
* @returns `Promise<ReadonlyArray<typescript.ReferenceEntry> | undefined>`
|
* @returns `Promise<ReadonlyArray<typescript.ReferenceEntry> | undefined>`
|
||||||
|
|
@ -334,10 +325,7 @@ declare namespace monaco.languages.typescript {
|
||||||
* Get references to the item at the given position in the file.
|
* Get references to the item at the given position in the file.
|
||||||
* @returns `Promise<typescript.ReferenceEntry[] | undefined>`
|
* @returns `Promise<typescript.ReferenceEntry[] | undefined>`
|
||||||
*/
|
*/
|
||||||
getReferencesAtPosition(
|
getReferencesAtPosition(fileName: string, position: number): Promise<any[] | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any[] | undefined>;
|
|
||||||
/**
|
/**
|
||||||
* Get outline entries for the item at the given position in the file.
|
* Get outline entries for the item at the given position in the file.
|
||||||
* @returns `Promise<typescript.NavigationBarItem[]>`
|
* @returns `Promise<typescript.NavigationBarItem[]>`
|
||||||
|
|
@ -348,10 +336,7 @@ declare namespace monaco.languages.typescript {
|
||||||
* @param options `typescript.FormatCodeOptions`
|
* @param options `typescript.FormatCodeOptions`
|
||||||
* @returns `Promise<typescript.TextChange[]>`
|
* @returns `Promise<typescript.TextChange[]>`
|
||||||
*/
|
*/
|
||||||
getFormattingEditsForDocument(
|
getFormattingEditsForDocument(fileName: string, options: any): Promise<any[]>;
|
||||||
fileName: string,
|
|
||||||
options: any
|
|
||||||
): Promise<any[]>;
|
|
||||||
/**
|
/**
|
||||||
* Get changes which should be applied to format the given range in the file.
|
* Get changes which should be applied to format the given range in the file.
|
||||||
* @param options `typescript.FormatCodeOptions`
|
* @param options `typescript.FormatCodeOptions`
|
||||||
|
|
@ -390,11 +375,7 @@ declare namespace monaco.languages.typescript {
|
||||||
* @param options `typescript.RenameInfoOptions`
|
* @param options `typescript.RenameInfoOptions`
|
||||||
* @returns `Promise<typescript.RenameInfo>`
|
* @returns `Promise<typescript.RenameInfo>`
|
||||||
*/
|
*/
|
||||||
getRenameInfo(
|
getRenameInfo(fileName: string, positon: number, options: any): Promise<any>;
|
||||||
fileName: string,
|
|
||||||
positon: number,
|
|
||||||
options: any
|
|
||||||
): Promise<any>;
|
|
||||||
/**
|
/**
|
||||||
* Get transpiled output for the given file.
|
* Get transpiled output for the given file.
|
||||||
* @returns `typescript.EmitOutput`
|
* @returns `typescript.EmitOutput`
|
||||||
|
|
@ -416,10 +397,6 @@ declare namespace monaco.languages.typescript {
|
||||||
export const typescriptVersion: string;
|
export const typescriptVersion: string;
|
||||||
export const typescriptDefaults: LanguageServiceDefaults;
|
export const typescriptDefaults: LanguageServiceDefaults;
|
||||||
export const javascriptDefaults: LanguageServiceDefaults;
|
export const javascriptDefaults: LanguageServiceDefaults;
|
||||||
export const getTypeScriptWorker: () => Promise<
|
export const getTypeScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
|
||||||
(...uris: Uri[]) => Promise<TypeScriptWorker>
|
export const getJavaScriptWorker: () => Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>>;
|
||||||
>;
|
|
||||||
export const getJavaScriptWorker: () => Promise<
|
|
||||||
(...uris: Uri[]) => Promise<TypeScriptWorker>
|
|
||||||
>;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,14 +44,8 @@ function bundleOne(moduleId, exclude) {
|
||||||
optimize: 'none'
|
optimize: 'none'
|
||||||
},
|
},
|
||||||
async function (buildResponse) {
|
async function (buildResponse) {
|
||||||
const devFilePath = path.join(
|
const devFilePath = path.join(REPO_ROOT, 'release/dev/' + moduleId + '.js');
|
||||||
REPO_ROOT,
|
const minFilePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js');
|
||||||
'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}...`);
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,7 @@ const generatedNote = `//
|
||||||
//
|
//
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const TYPESCRIPT_LIB_SOURCE = path.join(
|
const TYPESCRIPT_LIB_SOURCE = path.join(__dirname, '../node_modules/typescript/lib');
|
||||||
__dirname,
|
|
||||||
'../node_modules/typescript/lib'
|
|
||||||
);
|
|
||||||
const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
|
const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
|
@ -29,8 +26,7 @@ const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib');
|
||||||
const npmLsOutput = JSON.parse(
|
const npmLsOutput = JSON.parse(
|
||||||
child_process.execSync('npm ls typescript --depth=0 --json=true').toString()
|
child_process.execSync('npm ls typescript --depth=0 --json=true').toString()
|
||||||
);
|
);
|
||||||
const typeScriptDependencyVersion =
|
const typeScriptDependencyVersion = npmLsOutput.dependencies.typescript.version;
|
||||||
npmLsOutput.dependencies.typescript.version;
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServicesMetadata.ts'),
|
path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServicesMetadata.ts'),
|
||||||
|
|
@ -73,19 +69,20 @@ export const typescriptVersion = "${typeScriptDependencyVersion}";\n`
|
||||||
/(\/[*/]|^\s+\*[^/]).*\brequire\(.*/gm,
|
/(\/[*/]|^\s+\*[^/]).*\brequire\(.*/gm,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
const linesWithRequire = tsServicesNoCommentedRequire.match(
|
const linesWithRequire = tsServicesNoCommentedRequire.match(/^.*?\brequire\(.*$/gm);
|
||||||
/^.*?\brequire\(.*$/gm
|
|
||||||
);
|
|
||||||
|
|
||||||
// Allow error messages to include references to require() in their strings
|
// Allow error messages to include references to require() in their strings
|
||||||
const runtimeRequires =
|
const runtimeRequires =
|
||||||
linesWithRequire && linesWithRequire.filter((l) => !l.includes(': diag(') && !l.includes("ts.DiagnosticCategory"));
|
linesWithRequire &&
|
||||||
|
linesWithRequire.filter((l) => !l.includes(': diag(') && !l.includes('ts.DiagnosticCategory'));
|
||||||
|
|
||||||
if (runtimeRequires && runtimeRequires.length && linesWithRequire) {
|
if (runtimeRequires && runtimeRequires.length && linesWithRequire) {
|
||||||
console.error(
|
console.error(
|
||||||
'Found new require() calls on the following lines. These should be removed to avoid breaking webpack builds.\n'
|
'Found new require() calls on the following lines. These should be removed to avoid breaking webpack builds.\n'
|
||||||
);
|
);
|
||||||
console.error(runtimeRequires.map(r => `${r} (${tsServicesNoCommentedRequire.indexOf(r)})`).join('\n'));
|
console.error(
|
||||||
|
runtimeRequires.map((r) => `${r} (${tsServicesNoCommentedRequire.indexOf(r)})`).join('\n')
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,9 +160,7 @@ ${generatedNote}
|
||||||
/** Contains all the lib files */
|
/** Contains all the lib files */
|
||||||
export const libFileSet: Record<string, boolean> = {}
|
export const libFileSet: Record<string, boolean> = {}
|
||||||
`;
|
`;
|
||||||
var dtsFiles = fs
|
var dtsFiles = fs.readdirSync(TYPESCRIPT_LIB_SOURCE).filter((f) => f.includes('lib.'));
|
||||||
.readdirSync(TYPESCRIPT_LIB_SOURCE)
|
|
||||||
.filter((f) => f.includes('lib.'));
|
|
||||||
while (dtsFiles.length > 0) {
|
while (dtsFiles.length > 0) {
|
||||||
var name = dtsFiles.shift();
|
var name = dtsFiles.shift();
|
||||||
var output = readLibFile(name).replace(/\r\n/g, '\n');
|
var output = readLibFile(name).replace(/\r\n/g, '\n');
|
||||||
|
|
@ -173,14 +168,8 @@ export const libFileSet: Record<string, boolean> = {}
|
||||||
strIndexResult += `libFileSet['${name}'] = true;\n`;
|
strIndexResult += `libFileSet['${name}'] = true;\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.ts'), strLibResult);
|
||||||
path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.ts'),
|
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.index.ts'), strIndexResult);
|
||||||
strLibResult
|
|
||||||
);
|
|
||||||
fs.writeFileSync(
|
|
||||||
path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.index.ts'),
|
|
||||||
strIndexResult
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,7 @@ export function flattenDiagnosticMessageText(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayPartsToString(
|
function displayPartsToString(displayParts: ts.SymbolDisplayPart[] | undefined): string {
|
||||||
displayParts: ts.SymbolDisplayPart[] | undefined
|
|
||||||
): string {
|
|
||||||
if (displayParts) {
|
if (displayParts) {
|
||||||
return displayParts.map((displayPart) => displayPart.text).join('');
|
return displayParts.map((displayPart) => displayPart.text).join('');
|
||||||
}
|
}
|
||||||
|
|
@ -69,9 +67,7 @@ function displayPartsToString(
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
export abstract class Adapter {
|
export abstract class Adapter {
|
||||||
constructor(
|
constructor(protected _worker: (...uris: Uri[]) => Promise<TypeScriptWorker>) {}
|
||||||
protected _worker: (...uris: Uri[]) => Promise<TypeScriptWorker>
|
|
||||||
) {}
|
|
||||||
|
|
||||||
// protected _positionToOffset(model: editor.ITextModel, position: monaco.IPosition): number {
|
// protected _positionToOffset(model: editor.ITextModel, position: monaco.IPosition): number {
|
||||||
// return model.getOffsetAt(position);
|
// return model.getOffsetAt(position);
|
||||||
|
|
@ -81,10 +77,7 @@ export abstract class Adapter {
|
||||||
// return model.getPositionAt(offset);
|
// return model.getPositionAt(offset);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
protected _textSpanToRange(
|
protected _textSpanToRange(model: editor.ITextModel, span: ts.TextSpan): IRange {
|
||||||
model: editor.ITextModel,
|
|
||||||
span: ts.TextSpan
|
|
||||||
): IRange {
|
|
||||||
let p1 = model.getPositionAt(span.start);
|
let p1 = model.getPositionAt(span.start);
|
||||||
let p2 = model.getPositionAt(span.start + span.length);
|
let p2 = model.getPositionAt(span.start + span.length);
|
||||||
let { lineNumber: startLineNumber, column: startColumn } = p1;
|
let { lineNumber: startLineNumber, column: startColumn } = p1;
|
||||||
|
|
@ -100,9 +93,7 @@ export class LibFiles {
|
||||||
private _hasFetchedLibFiles: boolean;
|
private _hasFetchedLibFiles: boolean;
|
||||||
private _fetchLibFilesPromise: Promise<void> | null;
|
private _fetchLibFilesPromise: Promise<void> | null;
|
||||||
|
|
||||||
constructor(
|
constructor(private readonly _worker: (...uris: Uri[]) => Promise<TypeScriptWorker>) {
|
||||||
private readonly _worker: (...uris: Uri[]) => Promise<TypeScriptWorker>
|
|
||||||
) {
|
|
||||||
this._libFiles = {};
|
this._libFiles = {};
|
||||||
this._hasFetchedLibFiles = false;
|
this._hasFetchedLibFiles = false;
|
||||||
this._fetchLibFilesPromise = null;
|
this._fetchLibFilesPromise = null;
|
||||||
|
|
@ -124,11 +115,7 @@ export class LibFiles {
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
if (this.isLibFile(uri) && this._hasFetchedLibFiles) {
|
if (this.isLibFile(uri) && this._hasFetchedLibFiles) {
|
||||||
return editor.createModel(
|
return editor.createModel(this._libFiles[uri.path.slice(1)], 'javascript', uri);
|
||||||
this._libFiles[uri.path.slice(1)],
|
|
||||||
'javascript',
|
|
||||||
uri
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -239,9 +226,7 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this._disposables.push(this._defaults.onDidChange(recomputeDiagostics));
|
this._disposables.push(this._defaults.onDidChange(recomputeDiagostics));
|
||||||
this._disposables.push(
|
this._disposables.push(this._defaults.onDidExtraLibsChange(recomputeDiagostics));
|
||||||
this._defaults.onDidExtraLibsChange(recomputeDiagostics)
|
|
||||||
);
|
|
||||||
|
|
||||||
editor.getModels().forEach(onModelAdd);
|
editor.getModels().forEach(onModelAdd);
|
||||||
}
|
}
|
||||||
|
|
@ -286,9 +271,8 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
.reduce((p, c) => c.concat(p), [])
|
.reduce((p, c) => c.concat(p), [])
|
||||||
.filter(
|
.filter(
|
||||||
(d) =>
|
(d) =>
|
||||||
(
|
(this._defaults.getDiagnosticsOptions().diagnosticCodesToIgnore || []).indexOf(d.code) ===
|
||||||
this._defaults.getDiagnosticsOptions().diagnosticCodesToIgnore || []
|
-1
|
||||||
).indexOf(d.code) === -1
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fetch lib files if necessary
|
// Fetch lib files if necessary
|
||||||
|
|
@ -296,9 +280,7 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
.map((d) => d.relatedInformation || [])
|
.map((d) => d.relatedInformation || [])
|
||||||
.reduce((p, c) => c.concat(p), [])
|
.reduce((p, c) => c.concat(p), [])
|
||||||
.map((relatedInformation) =>
|
.map((relatedInformation) =>
|
||||||
relatedInformation.file
|
relatedInformation.file ? Uri.parse(relatedInformation.file.fileName) : null
|
||||||
? Uri.parse(relatedInformation.file.fileName)
|
|
||||||
: null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await this._libFiles.fetchLibFilesIfNecessary(relatedUris);
|
await this._libFiles.fetchLibFilesIfNecessary(relatedUris);
|
||||||
|
|
@ -315,20 +297,13 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _convertDiagnostics(
|
private _convertDiagnostics(model: editor.ITextModel, diag: ts.Diagnostic): editor.IMarkerData {
|
||||||
model: editor.ITextModel,
|
|
||||||
diag: ts.Diagnostic
|
|
||||||
): editor.IMarkerData {
|
|
||||||
const diagStart = diag.start || 0;
|
const diagStart = diag.start || 0;
|
||||||
const diagLength = diag.length || 1;
|
const diagLength = diag.length || 1;
|
||||||
const {
|
const { lineNumber: startLineNumber, column: startColumn } = model.getPositionAt(diagStart);
|
||||||
lineNumber: startLineNumber,
|
const { lineNumber: endLineNumber, column: endColumn } = model.getPositionAt(
|
||||||
column: startColumn
|
diagStart + diagLength
|
||||||
} = model.getPositionAt(diagStart);
|
);
|
||||||
const {
|
|
||||||
lineNumber: endLineNumber,
|
|
||||||
column: endColumn
|
|
||||||
} = model.getPositionAt(diagStart + diagLength);
|
|
||||||
|
|
||||||
const tags: MarkerTag[] = [];
|
const tags: MarkerTag[] = [];
|
||||||
if (diag.reportsUnnecessary) {
|
if (diag.reportsUnnecessary) {
|
||||||
|
|
@ -347,10 +322,7 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
message: flattenDiagnosticMessageText(diag.messageText, '\n'),
|
message: flattenDiagnosticMessageText(diag.messageText, '\n'),
|
||||||
code: diag.code.toString(),
|
code: diag.code.toString(),
|
||||||
tags,
|
tags,
|
||||||
relatedInformation: this._convertRelatedInformation(
|
relatedInformation: this._convertRelatedInformation(model, diag.relatedInformation)
|
||||||
model,
|
|
||||||
diag.relatedInformation
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,14 +347,12 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
}
|
}
|
||||||
const infoStart = info.start || 0;
|
const infoStart = info.start || 0;
|
||||||
const infoLength = info.length || 1;
|
const infoLength = info.length || 1;
|
||||||
const {
|
const { lineNumber: startLineNumber, column: startColumn } = relatedResource.getPositionAt(
|
||||||
lineNumber: startLineNumber,
|
infoStart
|
||||||
column: startColumn
|
);
|
||||||
} = relatedResource.getPositionAt(infoStart);
|
const { lineNumber: endLineNumber, column: endColumn } = relatedResource.getPositionAt(
|
||||||
const {
|
infoStart + infoLength
|
||||||
lineNumber: endLineNumber,
|
);
|
||||||
column: endColumn
|
|
||||||
} = relatedResource.getPositionAt(infoStart + infoLength);
|
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
resource: relatedResource.uri,
|
resource: relatedResource.uri,
|
||||||
|
|
@ -396,9 +366,7 @@ export class DiagnosticsAdapter extends Adapter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _tsDiagnosticCategoryToMarkerSeverity(
|
private _tsDiagnosticCategoryToMarkerSeverity(category: ts.DiagnosticCategory): MarkerSeverity {
|
||||||
category: ts.DiagnosticCategory
|
|
||||||
): MarkerSeverity {
|
|
||||||
switch (category) {
|
switch (category) {
|
||||||
case DiagnosticCategory.Error:
|
case DiagnosticCategory.Error:
|
||||||
return MarkerSeverity.Error;
|
return MarkerSeverity.Error;
|
||||||
|
|
@ -421,9 +389,7 @@ interface MyCompletionItem extends languages.CompletionItem {
|
||||||
position: Position;
|
position: Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SuggestAdapter
|
export class SuggestAdapter extends Adapter implements languages.CompletionItemProvider {
|
||||||
extends Adapter
|
|
||||||
implements languages.CompletionItemProvider {
|
|
||||||
public get triggerCharacters(): string[] {
|
public get triggerCharacters(): string[] {
|
||||||
return ['.'];
|
return ['.'];
|
||||||
}
|
}
|
||||||
|
|
@ -445,10 +411,7 @@ export class SuggestAdapter
|
||||||
const offset = model.getOffsetAt(position);
|
const offset = model.getOffsetAt(position);
|
||||||
|
|
||||||
const worker = await this._worker(resource);
|
const worker = await this._worker(resource);
|
||||||
const info = await worker.getCompletionsAtPosition(
|
const info = await worker.getCompletionsAtPosition(resource.toString(), offset);
|
||||||
resource.toString(),
|
|
||||||
offset
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!info || model.isDisposed()) {
|
if (!info || model.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -458,9 +421,7 @@ export class SuggestAdapter
|
||||||
let range = wordRange;
|
let range = wordRange;
|
||||||
if (entry.replacementSpan) {
|
if (entry.replacementSpan) {
|
||||||
const p1 = model.getPositionAt(entry.replacementSpan.start);
|
const p1 = model.getPositionAt(entry.replacementSpan.start);
|
||||||
const p2 = model.getPositionAt(
|
const p2 = model.getPositionAt(entry.replacementSpan.start + entry.replacementSpan.length);
|
||||||
entry.replacementSpan.start + entry.replacementSpan.length
|
|
||||||
);
|
|
||||||
range = new Range(p1.lineNumber, p1.column, p2.lineNumber, p2.column);
|
range = new Range(p1.lineNumber, p1.column, p2.lineNumber, p2.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -551,9 +512,7 @@ export class SuggestAdapter
|
||||||
return languages.CompletionItemKind.Property;
|
return languages.CompletionItemKind.Property;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static createDocumentationString(
|
private static createDocumentationString(details: ts.CompletionEntryDetails): string {
|
||||||
details: ts.CompletionEntryDetails
|
|
||||||
): string {
|
|
||||||
let documentationString = displayPartsToString(details.documentation);
|
let documentationString = displayPartsToString(details.documentation);
|
||||||
if (details.tags) {
|
if (details.tags) {
|
||||||
for (const tag of details.tags) {
|
for (const tag of details.tags) {
|
||||||
|
|
@ -576,9 +535,7 @@ function tagToString(tag: ts.JSDocTagInfo): string {
|
||||||
return tagLabel;
|
return tagLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SignatureHelpAdapter
|
export class SignatureHelpAdapter extends Adapter implements languages.SignatureHelpProvider {
|
||||||
extends Adapter
|
|
||||||
implements languages.SignatureHelpProvider {
|
|
||||||
public signatureHelpTriggerCharacters = ['(', ','];
|
public signatureHelpTriggerCharacters = ['(', ','];
|
||||||
|
|
||||||
public async provideSignatureHelp(
|
public async provideSignatureHelp(
|
||||||
|
|
@ -589,10 +546,7 @@ export class SignatureHelpAdapter
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
const offset = model.getOffsetAt(position);
|
const offset = model.getOffsetAt(position);
|
||||||
const worker = await this._worker(resource);
|
const worker = await this._worker(resource);
|
||||||
const info = await worker.getSignatureHelpItems(
|
const info = await worker.getSignatureHelpItems(resource.toString(), offset);
|
||||||
resource.toString(),
|
|
||||||
offset
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!info || model.isDisposed()) {
|
if (!info || model.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -641,9 +595,7 @@ export class SignatureHelpAdapter
|
||||||
|
|
||||||
// --- hover ------
|
// --- hover ------
|
||||||
|
|
||||||
export class QuickInfoAdapter
|
export class QuickInfoAdapter extends Adapter implements languages.HoverProvider {
|
||||||
extends Adapter
|
|
||||||
implements languages.HoverProvider {
|
|
||||||
public async provideHover(
|
public async provideHover(
|
||||||
model: editor.ITextModel,
|
model: editor.ITextModel,
|
||||||
position: Position,
|
position: Position,
|
||||||
|
|
@ -652,19 +604,14 @@ export class QuickInfoAdapter
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
const offset = model.getOffsetAt(position);
|
const offset = model.getOffsetAt(position);
|
||||||
const worker = await this._worker(resource);
|
const worker = await this._worker(resource);
|
||||||
const info = await worker.getQuickInfoAtPosition(
|
const info = await worker.getQuickInfoAtPosition(resource.toString(), offset);
|
||||||
resource.toString(),
|
|
||||||
offset
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!info || model.isDisposed()) {
|
if (!info || model.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentation = displayPartsToString(info.documentation);
|
const documentation = displayPartsToString(info.documentation);
|
||||||
const tags = info.tags
|
const tags = info.tags ? info.tags.map((tag) => tagToString(tag)).join(' \n\n') : '';
|
||||||
? info.tags.map((tag) => tagToString(tag)).join(' \n\n')
|
|
||||||
: '';
|
|
||||||
const contents = displayPartsToString(info.displayParts);
|
const contents = displayPartsToString(info.displayParts);
|
||||||
return {
|
return {
|
||||||
range: this._textSpanToRange(model, info.textSpan),
|
range: this._textSpanToRange(model, info.textSpan),
|
||||||
|
|
@ -682,9 +629,7 @@ export class QuickInfoAdapter
|
||||||
|
|
||||||
// --- occurrences ------
|
// --- occurrences ------
|
||||||
|
|
||||||
export class OccurrencesAdapter
|
export class OccurrencesAdapter extends Adapter implements languages.DocumentHighlightProvider {
|
||||||
extends Adapter
|
|
||||||
implements languages.DocumentHighlightProvider {
|
|
||||||
public async provideDocumentHighlights(
|
public async provideDocumentHighlights(
|
||||||
model: editor.ITextModel,
|
model: editor.ITextModel,
|
||||||
position: Position,
|
position: Position,
|
||||||
|
|
@ -693,10 +638,7 @@ export class OccurrencesAdapter
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
const offset = model.getOffsetAt(position);
|
const offset = model.getOffsetAt(position);
|
||||||
const worker = await this._worker(resource);
|
const worker = await this._worker(resource);
|
||||||
const entries = await worker.getOccurrencesAtPosition(
|
const entries = await worker.getOccurrencesAtPosition(resource.toString(), offset);
|
||||||
resource.toString(),
|
|
||||||
offset
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!entries || model.isDisposed()) {
|
if (!entries || model.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -731,10 +673,7 @@ export class DefinitionAdapter extends Adapter {
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
const offset = model.getOffsetAt(position);
|
const offset = model.getOffsetAt(position);
|
||||||
const worker = await this._worker(resource);
|
const worker = await this._worker(resource);
|
||||||
const entries = await worker.getDefinitionAtPosition(
|
const entries = await worker.getDefinitionAtPosition(resource.toString(), offset);
|
||||||
resource.toString(),
|
|
||||||
offset
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!entries || model.isDisposed()) {
|
if (!entries || model.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -766,9 +705,7 @@ export class DefinitionAdapter extends Adapter {
|
||||||
|
|
||||||
// --- references ------
|
// --- references ------
|
||||||
|
|
||||||
export class ReferenceAdapter
|
export class ReferenceAdapter extends Adapter implements languages.ReferenceProvider {
|
||||||
extends Adapter
|
|
||||||
implements languages.ReferenceProvider {
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _libFiles: LibFiles,
|
private readonly _libFiles: LibFiles,
|
||||||
worker: (...uris: Uri[]) => Promise<TypeScriptWorker>
|
worker: (...uris: Uri[]) => Promise<TypeScriptWorker>
|
||||||
|
|
@ -785,10 +722,7 @@ export class ReferenceAdapter
|
||||||
const resource = model.uri;
|
const resource = model.uri;
|
||||||
const offset = model.getOffsetAt(position);
|
const offset = model.getOffsetAt(position);
|
||||||
const worker = await this._worker(resource);
|
const worker = await this._worker(resource);
|
||||||
const entries = await worker.getReferencesAtPosition(
|
const entries = await worker.getReferencesAtPosition(resource.toString(), offset);
|
||||||
resource.toString(),
|
|
||||||
offset
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!entries || model.isDisposed()) {
|
if (!entries || model.isDisposed()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -820,9 +754,7 @@ export class ReferenceAdapter
|
||||||
|
|
||||||
// --- outline ------
|
// --- outline ------
|
||||||
|
|
||||||
export class OutlineAdapter
|
export class OutlineAdapter extends Adapter implements languages.DocumentSymbolProvider {
|
||||||
extends Adapter
|
|
||||||
implements languages.DocumentSymbolProvider {
|
|
||||||
public async provideDocumentSymbols(
|
public async provideDocumentSymbols(
|
||||||
model: editor.ITextModel,
|
model: editor.ITextModel,
|
||||||
token: CancellationToken
|
token: CancellationToken
|
||||||
|
|
@ -843,9 +775,7 @@ export class OutlineAdapter
|
||||||
let result: languages.DocumentSymbol = {
|
let result: languages.DocumentSymbol = {
|
||||||
name: item.text,
|
name: item.text,
|
||||||
detail: '',
|
detail: '',
|
||||||
kind: <languages.SymbolKind>(
|
kind: <languages.SymbolKind>(outlineTypeTable[item.kind] || languages.SymbolKind.Variable),
|
||||||
(outlineTypeTable[item.kind] || languages.SymbolKind.Variable)
|
|
||||||
),
|
|
||||||
range: this._textSpanToRange(model, item.spans[0]),
|
range: this._textSpanToRange(model, item.spans[0]),
|
||||||
selectionRange: this._textSpanToRange(model, item.spans[0]),
|
selectionRange: this._textSpanToRange(model, item.spans[0]),
|
||||||
tags: [],
|
tags: [],
|
||||||
|
|
@ -919,9 +849,7 @@ outlineTypeTable[Kind.localFunction] = languages.SymbolKind.Function;
|
||||||
// --- formatting ----
|
// --- formatting ----
|
||||||
|
|
||||||
export abstract class FormatHelper extends Adapter {
|
export abstract class FormatHelper extends Adapter {
|
||||||
protected static _convertOptions(
|
protected static _convertOptions(options: languages.FormattingOptions): ts.FormatCodeOptions {
|
||||||
options: languages.FormattingOptions
|
|
||||||
): ts.FormatCodeOptions {
|
|
||||||
return {
|
return {
|
||||||
ConvertTabsToSpaces: options.insertSpaces,
|
ConvertTabsToSpaces: options.insertSpaces,
|
||||||
TabSize: options.tabSize,
|
TabSize: options.tabSize,
|
||||||
|
|
@ -1020,9 +948,7 @@ export class FormatOnTypeAdapter
|
||||||
|
|
||||||
// --- code actions ------
|
// --- code actions ------
|
||||||
|
|
||||||
export class CodeActionAdaptor
|
export class CodeActionAdaptor extends FormatHelper implements languages.CodeActionProvider {
|
||||||
extends FormatHelper
|
|
||||||
implements languages.CodeActionProvider {
|
|
||||||
public async provideCodeActions(
|
public async provideCodeActions(
|
||||||
model: editor.ITextModel,
|
model: editor.ITextModel,
|
||||||
range: Range,
|
range: Range,
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,7 @@
|
||||||
|
|
||||||
import type * as mode from './tsMode';
|
import type * as mode from './tsMode';
|
||||||
import { typescriptVersion as tsversion } from './lib/typescriptServicesMetadata'; // do not import the whole typescriptServices here
|
import { typescriptVersion as tsversion } from './lib/typescriptServicesMetadata'; // do not import the whole typescriptServices here
|
||||||
import {
|
import { languages, Emitter, IEvent, IDisposable, Uri } from './fillers/monaco-editor-core';
|
||||||
languages,
|
|
||||||
Emitter,
|
|
||||||
IEvent,
|
|
||||||
IDisposable,
|
|
||||||
Uri
|
|
||||||
} from './fillers/monaco-editor-core';
|
|
||||||
|
|
||||||
//#region enums copied from typescript to prevent loading the entire typescriptServices ---
|
//#region enums copied from typescript to prevent loading the entire typescriptServices ---
|
||||||
|
|
||||||
|
|
@ -323,10 +317,7 @@ export interface TypeScriptWorker {
|
||||||
* Get code completions for the given file and position.
|
* Get code completions for the given file and position.
|
||||||
* @returns `Promise<typescript.CompletionInfo | undefined>`
|
* @returns `Promise<typescript.CompletionInfo | undefined>`
|
||||||
*/
|
*/
|
||||||
getCompletionsAtPosition(
|
getCompletionsAtPosition(fileName: string, position: number): Promise<any | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any | undefined>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get code completion details for the given file, position, and entry.
|
* Get code completion details for the given file, position, and entry.
|
||||||
|
|
@ -342,19 +333,13 @@ export interface TypeScriptWorker {
|
||||||
* Get signature help items for the item at the given file and position.
|
* Get signature help items for the item at the given file and position.
|
||||||
* @returns `Promise<typescript.SignatureHelpItems | undefined>`
|
* @returns `Promise<typescript.SignatureHelpItems | undefined>`
|
||||||
*/
|
*/
|
||||||
getSignatureHelpItems(
|
getSignatureHelpItems(fileName: string, position: number): Promise<any | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any | undefined>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get quick info for the item at the given position in the file.
|
* Get quick info for the item at the given position in the file.
|
||||||
* @returns `Promise<typescript.QuickInfo | undefined>`
|
* @returns `Promise<typescript.QuickInfo | undefined>`
|
||||||
*/
|
*/
|
||||||
getQuickInfoAtPosition(
|
getQuickInfoAtPosition(fileName: string, position: number): Promise<any | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any | undefined>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get other ranges which are related to the item at the given position in the file (often used for highlighting).
|
* Get other ranges which are related to the item at the given position in the file (often used for highlighting).
|
||||||
|
|
@ -378,10 +363,7 @@ export interface TypeScriptWorker {
|
||||||
* Get references to the item at the given position in the file.
|
* Get references to the item at the given position in the file.
|
||||||
* @returns `Promise<typescript.ReferenceEntry[] | undefined>`
|
* @returns `Promise<typescript.ReferenceEntry[] | undefined>`
|
||||||
*/
|
*/
|
||||||
getReferencesAtPosition(
|
getReferencesAtPosition(fileName: string, position: number): Promise<any[] | undefined>;
|
||||||
fileName: string,
|
|
||||||
position: number
|
|
||||||
): Promise<any[] | undefined>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get outline entries for the item at the given position in the file.
|
* Get outline entries for the item at the given position in the file.
|
||||||
|
|
@ -509,10 +491,7 @@ class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
filePath = _filePath;
|
filePath = _filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (this._extraLibs[filePath] && this._extraLibs[filePath].content === content) {
|
||||||
this._extraLibs[filePath] &&
|
|
||||||
this._extraLibs[filePath].content === content
|
|
||||||
) {
|
|
||||||
// no-op, there already exists an extra lib with this content
|
// no-op, there already exists an extra lib with this content
|
||||||
return {
|
return {
|
||||||
dispose: () => {}
|
dispose: () => {}
|
||||||
|
|
@ -553,8 +532,7 @@ class LanguageServiceDefaultsImpl implements LanguageServiceDefaults {
|
||||||
if (libs && libs.length > 0) {
|
if (libs && libs.length > 0) {
|
||||||
for (const lib of libs) {
|
for (const lib of libs) {
|
||||||
const filePath =
|
const filePath =
|
||||||
lib.filePath ||
|
lib.filePath || `ts:extralib-${Math.random().toString(36).substring(2, 15)}`;
|
||||||
`ts:extralib-${Math.random().toString(36).substring(2, 15)}`;
|
|
||||||
const content = lib.content;
|
const content = lib.content;
|
||||||
this._extraLibs[filePath] = {
|
this._extraLibs[filePath] = {
|
||||||
content: content,
|
content: content,
|
||||||
|
|
@ -627,15 +605,11 @@ export const javascriptDefaults: LanguageServiceDefaults = new LanguageServiceDe
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getTypeScriptWorker = (): Promise<
|
export const getTypeScriptWorker = (): Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>> => {
|
||||||
(...uris: Uri[]) => Promise<TypeScriptWorker>
|
|
||||||
> => {
|
|
||||||
return getMode().then((mode) => mode.getTypeScriptWorker());
|
return getMode().then((mode) => mode.getTypeScriptWorker());
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getJavaScriptWorker = (): Promise<
|
export const getJavaScriptWorker = (): Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>> => {
|
||||||
(...uris: Uri[]) => Promise<TypeScriptWorker>
|
|
||||||
> => {
|
|
||||||
return getMode().then((mode) => mode.getJavaScriptWorker());
|
return getMode().then((mode) => mode.getJavaScriptWorker());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ export function setupJavaScript(defaults: LanguageServiceDefaults): void {
|
||||||
javaScriptWorker = setupMode(defaults, 'javascript');
|
javaScriptWorker = setupMode(defaults, 'javascript');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getJavaScriptWorker(): Promise<
|
export function getJavaScriptWorker(): Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>> {
|
||||||
(...uris: Uri[]) => Promise<TypeScriptWorker>
|
|
||||||
> {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!javaScriptWorker) {
|
if (!javaScriptWorker) {
|
||||||
return reject('JavaScript not registered!');
|
return reject('JavaScript not registered!');
|
||||||
|
|
@ -33,9 +31,7 @@ export function getJavaScriptWorker(): Promise<
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTypeScriptWorker(): Promise<
|
export function getTypeScriptWorker(): Promise<(...uris: Uri[]) => Promise<TypeScriptWorker>> {
|
||||||
(...uris: Uri[]) => Promise<TypeScriptWorker>
|
|
||||||
> {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!typeScriptWorker) {
|
if (!typeScriptWorker) {
|
||||||
return reject('TypeScript not registered!');
|
return reject('TypeScript not registered!');
|
||||||
|
|
@ -56,18 +52,12 @@ function setupMode(
|
||||||
|
|
||||||
const libFiles = new languageFeatures.LibFiles(worker);
|
const libFiles = new languageFeatures.LibFiles(worker);
|
||||||
|
|
||||||
languages.registerCompletionItemProvider(
|
languages.registerCompletionItemProvider(modeId, new languageFeatures.SuggestAdapter(worker));
|
||||||
modeId,
|
|
||||||
new languageFeatures.SuggestAdapter(worker)
|
|
||||||
);
|
|
||||||
languages.registerSignatureHelpProvider(
|
languages.registerSignatureHelpProvider(
|
||||||
modeId,
|
modeId,
|
||||||
new languageFeatures.SignatureHelpAdapter(worker)
|
new languageFeatures.SignatureHelpAdapter(worker)
|
||||||
);
|
);
|
||||||
languages.registerHoverProvider(
|
languages.registerHoverProvider(modeId, new languageFeatures.QuickInfoAdapter(worker));
|
||||||
modeId,
|
|
||||||
new languageFeatures.QuickInfoAdapter(worker)
|
|
||||||
);
|
|
||||||
languages.registerDocumentHighlightProvider(
|
languages.registerDocumentHighlightProvider(
|
||||||
modeId,
|
modeId,
|
||||||
new languageFeatures.OccurrencesAdapter(worker)
|
new languageFeatures.OccurrencesAdapter(worker)
|
||||||
|
|
@ -80,10 +70,7 @@ function setupMode(
|
||||||
modeId,
|
modeId,
|
||||||
new languageFeatures.ReferenceAdapter(libFiles, worker)
|
new languageFeatures.ReferenceAdapter(libFiles, worker)
|
||||||
);
|
);
|
||||||
languages.registerDocumentSymbolProvider(
|
languages.registerDocumentSymbolProvider(modeId, new languageFeatures.OutlineAdapter(worker));
|
||||||
modeId,
|
|
||||||
new languageFeatures.OutlineAdapter(worker)
|
|
||||||
);
|
|
||||||
languages.registerDocumentRangeFormattingEditProvider(
|
languages.registerDocumentRangeFormattingEditProvider(
|
||||||
modeId,
|
modeId,
|
||||||
new languageFeatures.FormatAdapter(worker)
|
new languageFeatures.FormatAdapter(worker)
|
||||||
|
|
@ -92,14 +79,8 @@ function setupMode(
|
||||||
modeId,
|
modeId,
|
||||||
new languageFeatures.FormatOnTypeAdapter(worker)
|
new languageFeatures.FormatOnTypeAdapter(worker)
|
||||||
);
|
);
|
||||||
languages.registerCodeActionProvider(
|
languages.registerCodeActionProvider(modeId, new languageFeatures.CodeActionAdaptor(worker));
|
||||||
modeId,
|
languages.registerRenameProvider(modeId, new languageFeatures.RenameAdapter(worker));
|
||||||
new languageFeatures.CodeActionAdaptor(worker)
|
|
||||||
);
|
|
||||||
languages.registerRenameProvider(
|
|
||||||
modeId,
|
|
||||||
new languageFeatures.RenameAdapter(worker)
|
|
||||||
);
|
|
||||||
new languageFeatures.DiagnosticsAdapter(libFiles, defaults, modeId, worker);
|
new languageFeatures.DiagnosticsAdapter(libFiles, defaults, modeId, worker);
|
||||||
|
|
||||||
return worker;
|
return worker;
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,7 @@ import {
|
||||||
} from './monaco.contribution';
|
} from './monaco.contribution';
|
||||||
import { worker } from './fillers/monaco-editor-core';
|
import { worker } from './fillers/monaco-editor-core';
|
||||||
|
|
||||||
export class TypeScriptWorker
|
export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWorker {
|
||||||
implements ts.LanguageServiceHost, ITypeScriptWorker {
|
|
||||||
// --- model sync -----------------------
|
// --- model sync -----------------------
|
||||||
|
|
||||||
private _ctx: worker.IWorkerContext;
|
private _ctx: worker.IWorkerContext;
|
||||||
|
|
@ -35,9 +34,7 @@ export class TypeScriptWorker
|
||||||
}
|
}
|
||||||
|
|
||||||
getScriptFileNames(): string[] {
|
getScriptFileNames(): string[] {
|
||||||
let models = this._ctx
|
let models = this._ctx.getMirrorModels().map((model) => model.uri.toString());
|
||||||
.getMirrorModels()
|
|
||||||
.map((model) => model.uri.toString());
|
|
||||||
return models.concat(Object.keys(this._extraLibs));
|
return models.concat(Object.keys(this._extraLibs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,9 +111,7 @@ export class TypeScriptWorker
|
||||||
case 'jsx':
|
case 'jsx':
|
||||||
return ts.ScriptKind.JSX;
|
return ts.ScriptKind.JSX;
|
||||||
default:
|
default:
|
||||||
return this.getCompilationSettings().allowJs
|
return this.getCompilationSettings().allowJs ? ts.ScriptKind.JS : ts.ScriptKind.TS;
|
||||||
? ts.ScriptKind.JS
|
|
||||||
: ts.ScriptKind.TS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,9 +182,7 @@ export class TypeScriptWorker
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSuggestionDiagnostics(fileName: string): Promise<Diagnostic[]> {
|
async getSuggestionDiagnostics(fileName: string): Promise<Diagnostic[]> {
|
||||||
const diagnostics = this._languageService.getSuggestionDiagnostics(
|
const diagnostics = this._languageService.getSuggestionDiagnostics(fileName);
|
||||||
fileName
|
|
||||||
);
|
|
||||||
return TypeScriptWorker.clearFiles(diagnostics);
|
return TypeScriptWorker.clearFiles(diagnostics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,11 +195,7 @@ export class TypeScriptWorker
|
||||||
fileName: string,
|
fileName: string,
|
||||||
position: number
|
position: number
|
||||||
): Promise<ts.CompletionInfo | undefined> {
|
): Promise<ts.CompletionInfo | undefined> {
|
||||||
return this._languageService.getCompletionsAtPosition(
|
return this._languageService.getCompletionsAtPosition(fileName, position, undefined);
|
||||||
fileName,
|
|
||||||
position,
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCompletionEntryDetails(
|
async getCompletionEntryDetails(
|
||||||
|
|
@ -228,11 +217,7 @@ export class TypeScriptWorker
|
||||||
fileName: string,
|
fileName: string,
|
||||||
position: number
|
position: number
|
||||||
): Promise<ts.SignatureHelpItems | undefined> {
|
): Promise<ts.SignatureHelpItems | undefined> {
|
||||||
return this._languageService.getSignatureHelpItems(
|
return this._languageService.getSignatureHelpItems(fileName, position, undefined);
|
||||||
fileName,
|
|
||||||
position,
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getQuickInfoAtPosition(
|
async getQuickInfoAtPosition(
|
||||||
|
|
@ -263,9 +248,7 @@ export class TypeScriptWorker
|
||||||
return this._languageService.getReferencesAtPosition(fileName, position);
|
return this._languageService.getReferencesAtPosition(fileName, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNavigationBarItems(
|
async getNavigationBarItems(fileName: string): Promise<ts.NavigationBarItem[]> {
|
||||||
fileName: string
|
|
||||||
): Promise<ts.NavigationBarItem[]> {
|
|
||||||
return this._languageService.getNavigationBarItems(fileName);
|
return this._languageService.getNavigationBarItems(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -273,10 +256,7 @@ export class TypeScriptWorker
|
||||||
fileName: string,
|
fileName: string,
|
||||||
options: ts.FormatCodeOptions
|
options: ts.FormatCodeOptions
|
||||||
): Promise<ts.TextChange[]> {
|
): Promise<ts.TextChange[]> {
|
||||||
return this._languageService.getFormattingEditsForDocument(
|
return this._languageService.getFormattingEditsForDocument(fileName, options);
|
||||||
fileName,
|
|
||||||
options
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFormattingEditsForRange(
|
async getFormattingEditsForRange(
|
||||||
|
|
@ -285,12 +265,7 @@ export class TypeScriptWorker
|
||||||
end: number,
|
end: number,
|
||||||
options: ts.FormatCodeOptions
|
options: ts.FormatCodeOptions
|
||||||
): Promise<ts.TextChange[]> {
|
): Promise<ts.TextChange[]> {
|
||||||
return this._languageService.getFormattingEditsForRange(
|
return this._languageService.getFormattingEditsForRange(fileName, start, end, options);
|
||||||
fileName,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
options
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFormattingEditsAfterKeystroke(
|
async getFormattingEditsAfterKeystroke(
|
||||||
|
|
@ -299,12 +274,7 @@ export class TypeScriptWorker
|
||||||
ch: string,
|
ch: string,
|
||||||
options: ts.FormatCodeOptions
|
options: ts.FormatCodeOptions
|
||||||
): Promise<ts.TextChange[]> {
|
): Promise<ts.TextChange[]> {
|
||||||
return this._languageService.getFormattingEditsAfterKeystroke(
|
return this._languageService.getFormattingEditsAfterKeystroke(fileName, postion, ch, options);
|
||||||
fileName,
|
|
||||||
postion,
|
|
||||||
ch,
|
|
||||||
options
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async findRenameLocations(
|
async findRenameLocations(
|
||||||
|
|
@ -378,10 +348,7 @@ declare global {
|
||||||
var customTSWorkerFactory: CustomTSWebWorkerFactory | undefined;
|
var customTSWorkerFactory: CustomTSWebWorkerFactory | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function create(
|
export function create(ctx: worker.IWorkerContext, createData: ICreateData): TypeScriptWorker {
|
||||||
ctx: worker.IWorkerContext,
|
|
||||||
createData: ICreateData
|
|
||||||
): TypeScriptWorker {
|
|
||||||
let TSWorkerClass = TypeScriptWorker;
|
let TSWorkerClass = TypeScriptWorker;
|
||||||
if (createData.customWorkerPath) {
|
if (createData.customWorkerPath) {
|
||||||
if (typeof importScripts === 'undefined') {
|
if (typeof importScripts === 'undefined') {
|
||||||
|
|
@ -391,8 +358,7 @@ export function create(
|
||||||
} else {
|
} else {
|
||||||
importScripts(createData.customWorkerPath);
|
importScripts(createData.customWorkerPath);
|
||||||
|
|
||||||
const workerFactoryFunc: CustomTSWebWorkerFactory | undefined =
|
const workerFactoryFunc: CustomTSWebWorkerFactory | undefined = self.customTSWorkerFactory;
|
||||||
self.customTSWorkerFactory;
|
|
||||||
if (!workerFactoryFunc) {
|
if (!workerFactoryFunc) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The script at ${createData.customWorkerPath} does not add customTSWorkerFactory to self`
|
`The script at ${createData.customWorkerPath} does not add customTSWorkerFactory to self`
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,7 @@
|
||||||
"outDir": "../out/esm",
|
"outDir": "../out/esm",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"lib": [
|
"lib": ["dom", "es5", "es2015.collection", "es2015.iterable", "es2015.promise"],
|
||||||
"dom",
|
|
||||||
"es5",
|
|
||||||
"es2015.collection",
|
|
||||||
"es2015.iterable",
|
|
||||||
"es2015.promise"
|
|
||||||
],
|
|
||||||
"strict": true
|
"strict": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,7 @@
|
||||||
"outDir": "../out/amd",
|
"outDir": "../out/amd",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"lib": [
|
"lib": ["dom", "es5", "es2015.collection", "es2015.iterable", "es2015.promise"],
|
||||||
"dom",
|
|
||||||
"es5",
|
|
||||||
"es2015.collection",
|
|
||||||
"es2015.iterable",
|
|
||||||
"es2015.promise"
|
|
||||||
],
|
|
||||||
"strict": true
|
"strict": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,7 @@ export class WorkerManager {
|
||||||
this._defaults = defaults;
|
this._defaults = defaults;
|
||||||
this._worker = null;
|
this._worker = null;
|
||||||
this._client = null;
|
this._client = null;
|
||||||
this._configChangeListener = this._defaults.onDidChange(() =>
|
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
||||||
this._stopWorker()
|
|
||||||
);
|
|
||||||
this._updateExtraLibsToken = 0;
|
this._updateExtraLibsToken = 0;
|
||||||
this._extraLibsChangeListener = this._defaults.onDidExtraLibsChange(() =>
|
this._extraLibsChangeListener = this._defaults.onDidExtraLibsChange(() =>
|
||||||
this._updateExtraLibs()
|
this._updateExtraLibs()
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,7 @@
|
||||||
<body>
|
<body>
|
||||||
<h2>Monaco Editor TypeScript test page</h2>
|
<h2>Monaco Editor TypeScript test page</h2>
|
||||||
<button id="resetBtn">Reset Sample</button>
|
<button id="resetBtn">Reset Sample</button>
|
||||||
<div
|
<div id="container" style="width: 800px; height: 600px; border: 1px solid grey"></div>
|
||||||
id="container"
|
|
||||||
style="width: 800px; height: 600px; border: 1px solid grey"
|
|
||||||
></div>
|
|
||||||
<h3>Custom webworker</h3>
|
<h3>Custom webworker</h3>
|
||||||
<button id="logDTS">Log DTS</button>
|
<button id="logDTS">Log DTS</button>
|
||||||
<button id="getAST">Print AST to console</button>
|
<button id="getAST">Print AST to console</button>
|
||||||
|
|
@ -208,14 +205,11 @@
|
||||||
noLibCheck: true
|
noLibCheck: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var editor = monaco.editor.create(
|
var editor = monaco.editor.create(document.getElementById('container'), {
|
||||||
document.getElementById('container'),
|
value: localStorage.getItem('code') || getDefaultCode(),
|
||||||
{
|
language: 'typescript',
|
||||||
value: localStorage.getItem('code') || getDefaultCode(),
|
lightbulb: { enabled: true }
|
||||||
language: 'typescript',
|
});
|
||||||
lightbulb: { enabled: true }
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
editor.onDidChangeModelContent(() => {
|
editor.onDidChangeModelContent(() => {
|
||||||
const code = editor.getModel().getValue();
|
const code = editor.getModel().getValue();
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,9 @@
|
||||||
<body>
|
<body>
|
||||||
<h2>Monaco Editor TypeScript test page</h2>
|
<h2>Monaco Editor TypeScript test page</h2>
|
||||||
<button id="resetBtn">Reset Sample</button>
|
<button id="resetBtn">Reset Sample</button>
|
||||||
<div
|
<div id="container" style="width: 800px; height: 600px; border: 1px solid grey"></div>
|
||||||
id="container"
|
|
||||||
style="width: 800px; height: 600px; border: 1px solid grey"
|
|
||||||
></div>
|
|
||||||
<h3>Compiler settings</h3>
|
<h3>Compiler settings</h3>
|
||||||
<textarea
|
<textarea style="font-family: monospace" id="compilerOpts" cols="60" rows="30"></textarea><br />
|
||||||
style="font-family: monospace"
|
|
||||||
id="compilerOpts"
|
|
||||||
cols="60"
|
|
||||||
rows="30"
|
|
||||||
></textarea
|
|
||||||
><br />
|
|
||||||
<button id="updateCompilerSettingsBtn">Update compiler settings</button>
|
<button id="updateCompilerSettingsBtn">Update compiler settings</button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -187,14 +178,11 @@
|
||||||
'vs/basic-languages/monaco.contribution',
|
'vs/basic-languages/monaco.contribution',
|
||||||
'vs/language/typescript/monaco.contribution'
|
'vs/language/typescript/monaco.contribution'
|
||||||
], () => {
|
], () => {
|
||||||
var editor = monaco.editor.create(
|
var editor = monaco.editor.create(document.getElementById('container'), {
|
||||||
document.getElementById('container'),
|
value: localStorage.getItem('code') || getDefaultCode(),
|
||||||
{
|
language: 'typescript',
|
||||||
value: localStorage.getItem('code') || getDefaultCode(),
|
lightbulb: { enabled: true }
|
||||||
language: 'typescript',
|
});
|
||||||
lightbulb: { enabled: true }
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
editor.onDidChangeModelContent(() => {
|
editor.onDidChangeModelContent(() => {
|
||||||
const code = editor.getModel().getValue();
|
const code = editor.getModel().getValue();
|
||||||
|
|
@ -209,15 +197,11 @@
|
||||||
localStorage.getItem('compiler-opts') ||
|
localStorage.getItem('compiler-opts') ||
|
||||||
JSON.stringify(getDefaultComplierOpts(), null, 4);
|
JSON.stringify(getDefaultComplierOpts(), null, 4);
|
||||||
document.getElementById('compilerOpts').textContent = optsString;
|
document.getElementById('compilerOpts').textContent = optsString;
|
||||||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(
|
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(JSON.parse(optsString));
|
||||||
JSON.parse(optsString)
|
|
||||||
);
|
|
||||||
|
|
||||||
document.getElementById('updateCompilerSettingsBtn').onclick = () => {
|
document.getElementById('updateCompilerSettingsBtn').onclick = () => {
|
||||||
const newOpts = document.getElementById('compilerOpts').value;
|
const newOpts = document.getElementById('compilerOpts').value;
|
||||||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(
|
monaco.languages.typescript.typescriptDefaults.setCompilerOptions(JSON.parse(newOpts));
|
||||||
JSON.parse(newOpts)
|
|
||||||
);
|
|
||||||
localStorage.setItem('compiler-opts', newOpts);
|
localStorage.setItem('compiler-opts', newOpts);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue