mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 20:52:56 +01:00
Merge remote-tracking branch 'origin/master' into pr/orta/40
This commit is contained in:
commit
559bc5255a
14 changed files with 15714 additions and 8683 deletions
|
|
@ -23,26 +23,29 @@ enum IndentStyle {
|
|||
Smart = 2
|
||||
}
|
||||
|
||||
function flattenDiagnosticMessageText(messageText: string | ts.DiagnosticMessageChain, newLine: '\n'): string {
|
||||
if (typeof messageText === "string") {
|
||||
return messageText;
|
||||
} else {
|
||||
let diagnosticChain = messageText;
|
||||
let result = "";
|
||||
let indent = 0;
|
||||
while (diagnosticChain) {
|
||||
if (indent) {
|
||||
result += newLine;
|
||||
for (let i = 0; i < indent; i++) {
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
result += diagnosticChain.messageText;
|
||||
indent++;
|
||||
diagnosticChain = diagnosticChain.next;
|
||||
}
|
||||
return result;
|
||||
export function flattenDiagnosticMessageText(diag: string | ts.DiagnosticMessageChain | undefined, newLine: string, indent = 0): string {
|
||||
if (typeof diag === "string") {
|
||||
return diag;
|
||||
}
|
||||
else if (diag === undefined) {
|
||||
return "";
|
||||
}
|
||||
let result = "";
|
||||
if (indent) {
|
||||
result += newLine;
|
||||
|
||||
for (let i = 0; i < indent; i++) {
|
||||
result += " ";
|
||||
}
|
||||
}
|
||||
result += diag.messageText;
|
||||
indent++;
|
||||
if (diag.next) {
|
||||
for (const kid of diag.next) {
|
||||
result += flattenDiagnosticMessageText(kid, newLine, indent);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function displayPartsToString(displayParts: ts.SymbolDisplayPart[]): string {
|
||||
|
|
@ -326,7 +329,7 @@ export class SignatureHelpAdapter extends Adapter implements monaco.languages.Si
|
|||
|
||||
public signatureHelpTriggerCharacters = ['(', ','];
|
||||
|
||||
provideSignatureHelp(model: monaco.editor.IReadOnlyModel, position: Position, token: CancellationToken): Thenable<monaco.languages.SignatureHelp> {
|
||||
provideSignatureHelp(model: monaco.editor.IReadOnlyModel, position: Position, token: CancellationToken): Thenable<monaco.languages.SignatureHelpResult> {
|
||||
let resource = model.uri;
|
||||
return this._worker(resource).then(worker => worker.getSignatureHelpItems(resource.toString(), this._positionToOffset(resource, position))).then(info => {
|
||||
|
||||
|
|
@ -344,7 +347,6 @@ export class SignatureHelpAdapter extends Adapter implements monaco.languages.Si
|
|||
|
||||
let signature: monaco.languages.SignatureInformation = {
|
||||
label: '',
|
||||
documentation: null,
|
||||
parameters: []
|
||||
};
|
||||
|
||||
|
|
@ -365,8 +367,10 @@ export class SignatureHelpAdapter extends Adapter implements monaco.languages.Si
|
|||
ret.signatures.push(signature);
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
||||
return {
|
||||
value: ret,
|
||||
dispose() {}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -504,6 +508,7 @@ export class OutlineAdapter extends Adapter implements monaco.languages.Document
|
|||
kind: <monaco.languages.SymbolKind>(outlineTypeTable[item.kind] || monaco.languages.SymbolKind.Variable),
|
||||
range: this._textSpanToRange(resource, item.spans[0]),
|
||||
selectionRange: this._textSpanToRange(resource, item.spans[0]),
|
||||
tags: [],
|
||||
containerName: containerLabel
|
||||
};
|
||||
|
||||
|
|
@ -644,7 +649,7 @@ export class FormatOnTypeAdapter extends FormatHelper implements monaco.language
|
|||
|
||||
export class CodeActionAdaptor extends FormatHelper implements monaco.languages.CodeActionProvider {
|
||||
|
||||
public provideCodeActions(model: monaco.editor.ITextModel, range: Range, context: monaco.languages.CodeActionContext, token: CancellationToken): Promise<(monaco.languages.Command | monaco.languages.CodeAction)[]> {
|
||||
public provideCodeActions(model: monaco.editor.ITextModel, range: Range, context: monaco.languages.CodeActionContext, token: CancellationToken): Promise<monaco.languages.CodeActionList> {
|
||||
const resource = model.uri;
|
||||
|
||||
return this._worker(resource).then(worker => {
|
||||
|
|
@ -665,6 +670,11 @@ export class CodeActionAdaptor extends FormatHelper implements monaco.languages.
|
|||
}).map(fix => {
|
||||
return this._tsCodeFixActionToMonacoCodeAction(model, context, fix);
|
||||
})
|
||||
}).then(result => {
|
||||
return {
|
||||
actions: result,
|
||||
dispose: () => {}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -693,3 +703,47 @@ export class CodeActionAdaptor extends FormatHelper implements monaco.languages.
|
|||
return action;
|
||||
}
|
||||
}
|
||||
// --- rename ----
|
||||
|
||||
export class RenameAdapter extends Adapter implements monaco.languages.RenameProvider {
|
||||
|
||||
async provideRenameEdits(model: monaco.editor.ITextModel, position: Position, newName: string, token: CancellationToken): Promise<monaco.languages.WorkspaceEdit & monaco.languages.Rejection> {
|
||||
const resource = model.uri;
|
||||
const fileName = resource.toString();
|
||||
const offset = this._positionToOffset(resource, position);
|
||||
const worker = await this._worker(resource);
|
||||
|
||||
const renameInfo = await worker.getRenameInfo(fileName, offset, { allowRenameOfImportPath: false });
|
||||
if (renameInfo.canRename === false) { // use explicit comparison so that the discriminated union gets resolved properly
|
||||
return {
|
||||
edits: [],
|
||||
rejectReason: renameInfo.localizedErrorMessage
|
||||
};
|
||||
}
|
||||
if (renameInfo.fileToRename !== undefined) {
|
||||
throw new Error("Renaming files is not supported.");
|
||||
}
|
||||
|
||||
const renameLocations = await worker.findRenameLocations(fileName, offset, /*strings*/ false, /*comments*/ false, /*prefixAndSuffix*/ false);
|
||||
const fileNameToResourceTextEditMap: { [fileName: string]: monaco.languages.ResourceTextEdit } = {};
|
||||
|
||||
const edits: monaco.languages.ResourceTextEdit[] = [];
|
||||
for (const renameLocation of renameLocations) {
|
||||
if (!(renameLocation.fileName in fileNameToResourceTextEditMap)) {
|
||||
const resourceTextEdit = {
|
||||
edits: [],
|
||||
resource: monaco.Uri.parse(renameLocation.fileName)
|
||||
};
|
||||
fileNameToResourceTextEditMap[renameLocation.fileName] = resourceTextEdit;
|
||||
edits.push(resourceTextEdit);
|
||||
}
|
||||
|
||||
fileNameToResourceTextEditMap[renameLocation.fileName].edits.push({
|
||||
range: this._textSpanToRange(resource, renameLocation.textSpan),
|
||||
text: newName
|
||||
});
|
||||
}
|
||||
|
||||
return { edits };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1306
src/lib/typescriptServices.d.ts
vendored
1306
src/lib/typescriptServices.d.ts
vendored
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
|
@ -152,18 +152,21 @@ enum ModuleKind {
|
|||
UMD = 3,
|
||||
System = 4,
|
||||
ES2015 = 5,
|
||||
ESNext = 6
|
||||
ESNext = 99
|
||||
}
|
||||
|
||||
enum JsxEmit {
|
||||
None = 0,
|
||||
Preserve = 1,
|
||||
React = 2,
|
||||
ReactNative = 3
|
||||
}
|
||||
|
||||
enum NewLineKind {
|
||||
CarriageReturnLineFeed = 0,
|
||||
LineFeed = 1
|
||||
}
|
||||
|
||||
enum ScriptTarget {
|
||||
ES3 = 0,
|
||||
ES5 = 1,
|
||||
|
|
@ -171,10 +174,13 @@ enum ScriptTarget {
|
|||
ES2016 = 3,
|
||||
ES2017 = 4,
|
||||
ES2018 = 5,
|
||||
ESNext = 6,
|
||||
ES2019 = 6,
|
||||
ES2020 = 7,
|
||||
ESNext = 99,
|
||||
JSON = 100,
|
||||
Latest = 6
|
||||
Latest = ESNext,
|
||||
}
|
||||
|
||||
enum ModuleResolutionKind {
|
||||
Classic = 1,
|
||||
NodeJs = 2
|
||||
|
|
|
|||
9
src/monaco.d.ts
vendored
9
src/monaco.d.ts
vendored
|
|
@ -8,8 +8,9 @@ declare module monaco.languages.typescript {
|
|||
UMD = 3,
|
||||
System = 4,
|
||||
ES2015 = 5,
|
||||
ESNext = 6
|
||||
ESNext = 99
|
||||
}
|
||||
|
||||
enum JsxEmit {
|
||||
None = 0,
|
||||
Preserve = 1,
|
||||
|
|
@ -28,9 +29,11 @@ declare module monaco.languages.typescript {
|
|||
ES2016 = 3,
|
||||
ES2017 = 4,
|
||||
ES2018 = 5,
|
||||
ESNext = 6,
|
||||
ES2019 = 6,
|
||||
ES2020 = 7,
|
||||
ESNext = 99,
|
||||
JSON = 100,
|
||||
Latest = 6
|
||||
Latest = ESNext,
|
||||
}
|
||||
|
||||
export enum ModuleResolutionKind {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ function setupMode(defaults: LanguageServiceDefaultsImpl, modeId: string): (firs
|
|||
monaco.languages.registerDocumentRangeFormattingEditProvider(modeId, new languageFeatures.FormatAdapter(worker));
|
||||
monaco.languages.registerOnTypeFormattingEditProvider(modeId, new languageFeatures.FormatOnTypeAdapter(worker));
|
||||
monaco.languages.registerCodeActionProvider(modeId, new languageFeatures.CodeActionAdaptor(worker));
|
||||
|
||||
monaco.languages.registerRenameProvider(modeId, new languageFeatures.RenameAdapter(worker));
|
||||
new languageFeatures.DiagnostcsAdapter(defaults, modeId, worker);
|
||||
|
||||
return worker;
|
||||
|
|
|
|||
|
|
@ -202,6 +202,14 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
|
|||
return Promise.resolve(this._languageService.getFormattingEditsAfterKeystroke(fileName, postion, ch, options));
|
||||
}
|
||||
|
||||
findRenameLocations(fileName: string, positon: number, findInStrings: boolean, findInComments: boolean, providePrefixAndSuffixTextForRename: boolean): Promise<readonly ts.RenameLocation[]> {
|
||||
return Promise.resolve(this._languageService.findRenameLocations(fileName, positon, findInStrings, findInComments, providePrefixAndSuffixTextForRename));
|
||||
}
|
||||
|
||||
getRenameInfo(fileName: string, positon: number, options: ts.RenameInfoOptions): Promise<ts.RenameInfo> {
|
||||
return Promise.resolve(this._languageService.getRenameInfo(fileName, positon, options));
|
||||
}
|
||||
|
||||
getEmitOutput(fileName: string): Promise<ts.EmitOutput> {
|
||||
return Promise.resolve(this._languageService.getEmitOutput(fileName));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue