|
@@ -23,26 +23,29 @@ enum IndentStyle {
|
|
Smart = 2
|
|
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;
|
|
|
|
|
|
+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;
|
|
|
|
}
|
|
}
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
|
|
function displayPartsToString(displayParts: ts.SymbolDisplayPart[]): string {
|
|
function displayPartsToString(displayParts: ts.SymbolDisplayPart[]): string {
|
|
@@ -326,7 +329,7 @@ export class SignatureHelpAdapter extends Adapter implements monaco.languages.Si
|
|
|
|
|
|
public signatureHelpTriggerCharacters = ['(', ','];
|
|
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;
|
|
let resource = model.uri;
|
|
return this._worker(resource).then(worker => worker.getSignatureHelpItems(resource.toString(), this._positionToOffset(resource, position))).then(info => {
|
|
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 = {
|
|
let signature: monaco.languages.SignatureInformation = {
|
|
label: '',
|
|
label: '',
|
|
- documentation: null,
|
|
|
|
parameters: []
|
|
parameters: []
|
|
};
|
|
};
|
|
|
|
|
|
@@ -365,8 +367,10 @@ export class SignatureHelpAdapter extends Adapter implements monaco.languages.Si
|
|
ret.signatures.push(signature);
|
|
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),
|
|
kind: <monaco.languages.SymbolKind>(outlineTypeTable[item.kind] || monaco.languages.SymbolKind.Variable),
|
|
range: this._textSpanToRange(resource, item.spans[0]),
|
|
range: this._textSpanToRange(resource, item.spans[0]),
|
|
selectionRange: this._textSpanToRange(resource, item.spans[0]),
|
|
selectionRange: this._textSpanToRange(resource, item.spans[0]),
|
|
|
|
+ tags: [],
|
|
containerName: containerLabel
|
|
containerName: containerLabel
|
|
};
|
|
};
|
|
|
|
|
|
@@ -644,7 +649,7 @@ export class FormatOnTypeAdapter extends FormatHelper implements monaco.language
|
|
|
|
|
|
export class CodeActionAdaptor extends FormatHelper implements monaco.languages.CodeActionProvider {
|
|
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;
|
|
const resource = model.uri;
|
|
|
|
|
|
return this._worker(resource).then(worker => {
|
|
return this._worker(resource).then(worker => {
|
|
@@ -665,6 +670,11 @@ export class CodeActionAdaptor extends FormatHelper implements monaco.languages.
|
|
}).map(fix => {
|
|
}).map(fix => {
|
|
return this._tsCodeFixActionToMonacoCodeAction(model, context, 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;
|
|
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 };
|
|
|
|
+ }
|
|
|
|
+}
|