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