From 834ab9e1d07155df63f7ee1a8a36e3e8f557732a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Wed, 21 Feb 2024 12:01:57 +0100 Subject: [PATCH 1/2] fix: remove more useless stuff from extensions --- rollup.config.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rollup.config.ts b/rollup.config.ts index ff64d8f..ff935ee 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -103,17 +103,23 @@ ${files.map((_, index) => ` whenReady${index}()`).join(',\n')} breakpoints, taskDefinitions, viewsWelcome, + terminal, + viewsContainers, ...remainingContribute - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } = manifest.contributes as any + } = manifest.contributes ?? {} const { + activationEvents, + devDependencies, + dependencies, + scripts, browser, main, l10n, extensionDependencies, // for pure-d that requires hbenl.vscode-test-explorer ...remainingManifest - } = manifest + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } = manifest as any return { ...remainingManifest, From 5059bd6e4da20d1658469d45b49e14e4bde3255b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Wed, 21 Feb 2024 12:02:26 +0100 Subject: [PATCH 2/2] fix: fix/improve hideCodeWithoutDecoration using source --- src/tools.ts | 39 +++++++++++---------------------------- src/types/monaco.d.ts | 2 +- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/tools.ts b/src/tools.ts index 897e575..cf8a5db 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -182,18 +182,20 @@ export function lockCodeWithoutDecoration ( return disposableStore } +let hideCodeWithoutDecorationCounter = 0 export function hideCodeWithoutDecoration (editor: monaco.editor.ICodeEditor, decorationFilter: (decoration: monaco.editor.IModelDecoration) => boolean): monaco.IDisposable { - let otherHiddenAreas: monaco.IRange[] = editor._getViewModel()?.getHiddenAreas() ?? [] - function getHiddenAreas () { + const hideId = `hideCodeWithoutDecoration:${hideCodeWithoutDecorationCounter++}` + + function updateHiddenAreas (): void { const model = editor.getModel() if (model == null) { - return [] + return } const decorations = model.getAllDecorations() .filter(decorationFilter) if (decorations.length === 0) { - return otherHiddenAreas + return } const ranges = decorations @@ -218,40 +220,22 @@ export function hideCodeWithoutDecoration (editor: monaco.editor.ICodeEditor, de } }, []) - let hiddenAreas: monaco.IRange[] = [...otherHiddenAreas] + const hiddenAreas: monaco.IRange[] = [] let position = new monaco.Position(1, 1) for (const range of ranges) { const startPosition = model.modifyPosition(range.getStartPosition(), -1) const endPosition = model.modifyPosition(range.getEndPosition(), 1) - hiddenAreas = [ - ...hiddenAreas, - monaco.Range.fromPositions(position, startPosition) - ] + hiddenAreas.push(monaco.Range.fromPositions(position, startPosition)) position = endPosition } - hiddenAreas = [ - ...hiddenAreas, - monaco.Range.fromPositions(position, model.getFullModelRange().getEndPosition()) - ] - - return hiddenAreas - } - - const originalSetHiddenAreas = editor.setHiddenAreas.bind(editor) - function updateHiddenAreas () { - originalSetHiddenAreas(getHiddenAreas()) - } + hiddenAreas.push(monaco.Range.fromPositions(position, model.getFullModelRange().getEndPosition())) - // Hack to make it work with the folding service calling setHiddenAreas with its own areas - editor.setHiddenAreas = (ranges) => { - otherHiddenAreas = ranges - updateHiddenAreas() + editor.setHiddenAreas(hiddenAreas, hideId) } const disposableStore = new DisposableStore() disposableStore.add(editor.onDidChangeModel(() => { - otherHiddenAreas = editor._getViewModel()?.getHiddenAreas() ?? [] updateHiddenAreas() })) disposableStore.add(editor.onDidChangeModelDecorations(() => { @@ -261,8 +245,7 @@ export function hideCodeWithoutDecoration (editor: monaco.editor.ICodeEditor, de disposableStore.add({ dispose () { - editor.setHiddenAreas = originalSetHiddenAreas - editor.setHiddenAreas(otherHiddenAreas) + editor.setHiddenAreas([], hideId) } }) diff --git a/src/types/monaco.d.ts b/src/types/monaco.d.ts index 2ca02f2..e7b54f4 100644 --- a/src/types/monaco.d.ts +++ b/src/types/monaco.d.ts @@ -5,7 +5,7 @@ declare module 'monaco-editor' { interface ICodeEditor { // This method is internal and is supposed to be used by the folding feature // We still use it to hide parts of the code in the `hideCodeWithoutDecoration` function - setHiddenAreas(ranges: IRange[]): void + setHiddenAreas(ranges: IRange[], source?: unknown): void _getViewModel(): { getHiddenAreas(): IRange[]