diff --git a/build/releaseMetadata.ts b/build/releaseMetadata.ts index 3fb6f7c6..17a530ff 100644 --- a/build/releaseMetadata.ts +++ b/build/releaseMetadata.ts @@ -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'); + } + } } ); } diff --git a/src/language/typescript/languageFeatures.ts b/src/language/typescript/languageFeatures.ts index 15b0e7fe..9f6cbb77 100644 --- a/src/language/typescript/languageFeatures.ts +++ b/src/language/typescript/languageFeatures.ts @@ -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; } } diff --git a/src/language/typescript/monaco.contribution.ts b/src/language/typescript/monaco.contribution.ts index 9b6a6ae8..4220bcfb 100644 --- a/src/language/typescript/monaco.contribution.ts +++ b/src/language/typescript/monaco.contribution.ts @@ -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. diff --git a/src/language/typescript/tsMode.ts b/src/language/typescript/tsMode.ts index 8cdab6fa..0f6d4d21 100644 --- a/src/language/typescript/tsMode.ts +++ b/src/language/typescript/tsMode.ts @@ -86,7 +86,7 @@ function setupMode( providers.push( languages.registerDocumentHighlightProvider( modeId, - new languageFeatures.OccurrencesAdapter(worker) + new languageFeatures.DocumentHighlightAdapter(worker) ) ); } diff --git a/src/language/typescript/tsWorker.ts b/src/language/typescript/tsWorker.ts index 65601f84..51882423 100644 --- a/src/language/typescript/tsWorker.ts +++ b/src/language/typescript/tsWorker.ts @@ -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( diff --git a/website/src/website/data/playground-samples/creating-the-editor/hard-wrapping/sample.js b/website/src/website/data/playground-samples/creating-the-editor/hard-wrapping/sample.js index 63674810..a6f08dc0 100644 --- a/website/src/website/data/playground-samples/creating-the-editor/hard-wrapping/sample.js +++ b/website/src/website/data/playground-samples/creating-the-editor/hard-wrapping/sample.js @@ -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", });