diff --git a/CHANGELOG.md b/CHANGELOG.md index 93e31674b..51985e76c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - the completer now uses `filterText` and `sortText` if available to better filter and sort completions ([#520], [#523]) - completer `suppressInvokeIn` setting was removed; `suppressContinuousHintingIn` and `suppressTriggerCharacterIn` settings were added ([#521]) - `suppressContinuousHintingIn` by default includes `def` to improve the experience when writing function names ([#521]) + - long file paths are now collapsed if composed of more than two segments to avoid status popover and diagnostics panel getting too wide ([#524]) - bug fixes: - user-invoked completion in strings works again ([#521]) @@ -21,6 +22,7 @@ [#521]: https://github.com/krassowski/jupyterlab-lsp/pull/521 [#522]: https://github.com/krassowski/jupyterlab-lsp/pull/522 [#523]: https://github.com/krassowski/jupyterlab-lsp/pull/523 +[#524]: https://github.com/krassowski/jupyterlab-lsp/pull/524 ### `@krassowski/jupyterlab-lsp 3.3.1` (2020-02-07) diff --git a/packages/jupyterlab-lsp/src/components/utils.spec.ts b/packages/jupyterlab-lsp/src/components/utils.spec.ts new file mode 100644 index 000000000..94be49c85 --- /dev/null +++ b/packages/jupyterlab-lsp/src/components/utils.spec.ts @@ -0,0 +1,53 @@ +import { get_breadcrumbs } from './utils'; +import { VirtualDocument } from '../virtual/document'; +import { WidgetAdapter } from '../adapters/adapter'; +import { IDocumentWidget } from '@jupyterlab/docregistry'; + +function create_dummy_document(options: Partial) { + return new VirtualDocument({ + language: 'python', + foreign_code_extractors: {}, + overrides_registry: {}, + path: 'Untitled.ipynb.py', + file_extension: 'py', + has_lsp_supported_file: false, + ...options + }); +} + +describe('get_breadcrumbs', () => { + it('should collapse long paths', () => { + let document = create_dummy_document({ + path: 'dir1/dir2/Test.ipynb' + }); + let breadcrumbs = get_breadcrumbs(document, { + has_multiple_editors: false + } as WidgetAdapter); + expect(breadcrumbs[0].props['title']).toBe('dir1/dir2/Test.ipynb'); + expect(breadcrumbs[0].props['children']).toBe('dir1/.../Test.ipynb'); + }); + + it('should trim the extra filename suffix for files created out of notebooks', () => { + let document = create_dummy_document({ + path: 'Test.ipynb.py', + file_extension: 'py', + has_lsp_supported_file: false + }); + let breadcrumbs = get_breadcrumbs(document, { + has_multiple_editors: false + } as WidgetAdapter); + expect(breadcrumbs[0].props['children']).toBe('Test.ipynb'); + }); + + it('should not trim the filename suffix for standalone files', () => { + let document = create_dummy_document({ + path: 'test.py', + file_extension: 'py', + has_lsp_supported_file: true + }); + let breadcrumbs = get_breadcrumbs(document, { + has_multiple_editors: false + } as WidgetAdapter); + expect(breadcrumbs[0].props['children']).toBe('test.py'); + }); +}); diff --git a/packages/jupyterlab-lsp/src/components/utils.tsx b/packages/jupyterlab-lsp/src/components/utils.tsx index 0127cd65b..1f192d565 100644 --- a/packages/jupyterlab-lsp/src/components/utils.tsx +++ b/packages/jupyterlab-lsp/src/components/utils.tsx @@ -5,7 +5,8 @@ import React from 'react'; export function get_breadcrumbs( document: VirtualDocument, - adapter: WidgetAdapter + adapter: WidgetAdapter, + collapse = true ): JSX.Element[] { return document.ancestry.map((document: VirtualDocument) => { if (!document.parent) { @@ -16,7 +17,18 @@ export function get_breadcrumbs( ) { path = path.slice(0, -document.file_extension.length - 1); } - return {path}; + const full_path = path; + if (collapse) { + let parts = path.split('/'); + if (parts.length > 2) { + path = parts[0] + '/.../' + parts[parts.length - 1]; + } + } + return ( + + {path} + + ); } if (!document.virtual_lines.size) { return Empty document;