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