mirror of
https://github.com/microsoft/monaco-editor.git
synced 2024-11-25 16:35:44 +08:00
Merge branch 'microsoft:main' into patch-2
This commit is contained in:
commit
8629931e99
@ -185,6 +185,15 @@ exports.languages = ${JSON.stringify(languages, null, ' ')};
|
||||
const jsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm/metadata.js');
|
||||
ensureDir(path.dirname(jsDestination));
|
||||
fs.writeFileSync(jsDestination, jsContents.replace(/\r\n/g, '\n'));
|
||||
|
||||
for (const feature of [...features, ...languages]) {
|
||||
const entries = [].concat(feature.entry);
|
||||
for (const entry of entries) {
|
||||
const dtsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm', entry) + '.d.ts';
|
||||
ensureDir(path.dirname(dtsDestination));
|
||||
fs.writeFileSync(dtsDestination, 'export {}\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -715,7 +715,10 @@ export class QuickInfoAdapter extends Adapter implements languages.HoverProvider
|
||||
|
||||
// --- occurrences ------
|
||||
|
||||
export class OccurrencesAdapter extends Adapter implements languages.DocumentHighlightProvider {
|
||||
export class DocumentHighlightAdapter
|
||||
extends Adapter
|
||||
implements languages.DocumentHighlightProvider
|
||||
{
|
||||
public async provideDocumentHighlights(
|
||||
model: editor.ITextModel,
|
||||
position: Position,
|
||||
@ -729,19 +732,24 @@ export class OccurrencesAdapter extends Adapter implements languages.DocumentHig
|
||||
return;
|
||||
}
|
||||
|
||||
const entries = await worker.getOccurrencesAtPosition(resource.toString(), offset);
|
||||
const entries = await worker.getDocumentHighlights(resource.toString(), offset, [
|
||||
resource.toString()
|
||||
]);
|
||||
|
||||
if (!entries || model.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
return entries.map((entry) => {
|
||||
return <languages.DocumentHighlight>{
|
||||
range: this._textSpanToRange(model, entry.textSpan),
|
||||
kind: entry.isWriteAccess
|
||||
? languages.DocumentHighlightKind.Write
|
||||
: languages.DocumentHighlightKind.Text
|
||||
};
|
||||
return entries.flatMap((entry) => {
|
||||
return entry.highlightSpans.map((highlightSpans) => {
|
||||
return <languages.DocumentHighlight>{
|
||||
range: this._textSpanToRange(model, highlightSpans.textSpan),
|
||||
kind:
|
||||
highlightSpans.kind === 'writtenReference'
|
||||
? languages.DocumentHighlightKind.Write
|
||||
: languages.DocumentHighlightKind.Text
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -865,39 +873,31 @@ export class OutlineAdapter extends Adapter implements languages.DocumentSymbolP
|
||||
return;
|
||||
}
|
||||
|
||||
const items = await worker.getNavigationBarItems(resource.toString());
|
||||
const root = await worker.getNavigationTree(resource.toString());
|
||||
|
||||
if (!items || model.isDisposed()) {
|
||||
if (!root || model.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const convert = (
|
||||
bucket: languages.DocumentSymbol[],
|
||||
item: ts.NavigationBarItem,
|
||||
item: ts.NavigationTree,
|
||||
containerLabel?: string
|
||||
): void => {
|
||||
let result: languages.DocumentSymbol = {
|
||||
): languages.DocumentSymbol => {
|
||||
const result: languages.DocumentSymbol = {
|
||||
name: item.text,
|
||||
detail: '',
|
||||
kind: <languages.SymbolKind>(outlineTypeTable[item.kind] || languages.SymbolKind.Variable),
|
||||
range: this._textSpanToRange(model, item.spans[0]),
|
||||
selectionRange: this._textSpanToRange(model, item.spans[0]),
|
||||
tags: []
|
||||
tags: [],
|
||||
children: item.childItems?.map((child) => convert(child, result.name)),
|
||||
containerName: containerLabel
|
||||
};
|
||||
|
||||
if (containerLabel) result.containerName = containerLabel;
|
||||
|
||||
if (item.childItems && item.childItems.length > 0) {
|
||||
for (let child of item.childItems) {
|
||||
convert(bucket, child, result.name);
|
||||
}
|
||||
}
|
||||
|
||||
bucket.push(result);
|
||||
return result;
|
||||
};
|
||||
|
||||
let result: languages.DocumentSymbol[] = [];
|
||||
items.forEach((item) => convert(result, item));
|
||||
// Exclude the root node, as it alwas spans the entire document.
|
||||
const result = root.childItems ? root.childItems.map((item) => convert(item)) : [];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -440,13 +440,10 @@ export interface TypeScriptWorker {
|
||||
*/
|
||||
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>`
|
||||
*/
|
||||
getOccurrencesAtPosition(
|
||||
getDocumentHighlights(
|
||||
fileName: string,
|
||||
position: number
|
||||
position: number,
|
||||
filesToSearch: string[]
|
||||
): Promise<ReadonlyArray<any> | undefined>;
|
||||
|
||||
/**
|
||||
@ -466,9 +463,9 @@ export interface TypeScriptWorker {
|
||||
|
||||
/**
|
||||
* Get outline entries for the item at the given position in the file.
|
||||
* @returns `Promise<typescript.NavigationBarItem[]>`
|
||||
* @returns `Promise<typescript.NavigationTree | undefined>`
|
||||
*/
|
||||
getNavigationBarItems(fileName: string): Promise<any[]>;
|
||||
getNavigationTree(fileName: string): Promise<any | undefined>;
|
||||
|
||||
/**
|
||||
* Get changes which should be applied to format the given file.
|
||||
|
@ -86,7 +86,7 @@ function setupMode(
|
||||
providers.push(
|
||||
languages.registerDocumentHighlightProvider(
|
||||
modeId,
|
||||
new languageFeatures.OccurrencesAdapter(worker)
|
||||
new languageFeatures.DocumentHighlightAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -299,14 +299,15 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
|
||||
return this._languageService.getQuickInfoAtPosition(fileName, position);
|
||||
}
|
||||
|
||||
async getOccurrencesAtPosition(
|
||||
async getDocumentHighlights(
|
||||
fileName: string,
|
||||
position: number
|
||||
): Promise<ReadonlyArray<ts.ReferenceEntry> | undefined> {
|
||||
position: number,
|
||||
filesToSearch: string[]
|
||||
): Promise<ReadonlyArray<ts.DocumentHighlights> | undefined> {
|
||||
if (fileNameIsLib(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
return this._languageService.getOccurrencesAtPosition(fileName, position);
|
||||
return this._languageService.getDocumentHighlights(fileName, position, filesToSearch);
|
||||
}
|
||||
|
||||
async getDefinitionAtPosition(
|
||||
@ -329,11 +330,11 @@ export class TypeScriptWorker implements ts.LanguageServiceHost, ITypeScriptWork
|
||||
return this._languageService.getReferencesAtPosition(fileName, position);
|
||||
}
|
||||
|
||||
async getNavigationBarItems(fileName: string): Promise<ts.NavigationBarItem[]> {
|
||||
async getNavigationTree(fileName: string): Promise<ts.NavigationTree | undefined> {
|
||||
if (fileNameIsLib(fileName)) {
|
||||
return [];
|
||||
return undefined;
|
||||
}
|
||||
return this._languageService.getNavigationBarItems(fileName);
|
||||
return this._languageService.getNavigationTree(fileName);
|
||||
}
|
||||
|
||||
async getFormattingEditsForDocument(
|
||||
|
@ -8,9 +8,6 @@ var editor = monaco.editor.create(document.getElementById("container"), {
|
||||
wordWrap: "wordWrapColumn",
|
||||
wordWrapColumn: 40,
|
||||
|
||||
// Set this to false to not auto word wrap minified files
|
||||
wordWrapMinified: true,
|
||||
|
||||
// try "same", "indent" or "none"
|
||||
wrappingIndent: "indent",
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user