Skip to content

Commit

Permalink
Merge pull request #524 from krassowski/collapse_long_paths
Browse files Browse the repository at this point in the history
Collapse paths for files deep in subfolders
  • Loading branch information
krassowski authored Feb 14, 2021
2 parents c3e90ec + fd0fe88 commit d6f836e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)

Expand Down
53 changes: 53 additions & 0 deletions packages/jupyterlab-lsp/src/components/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -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<VirtualDocument.IOptions>) {
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<IDocumentWidget>);
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<IDocumentWidget>);
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<IDocumentWidget>);
expect(breadcrumbs[0].props['children']).toBe('test.py');
});
});
16 changes: 14 additions & 2 deletions packages/jupyterlab-lsp/src/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import React from 'react';

export function get_breadcrumbs(
document: VirtualDocument,
adapter: WidgetAdapter<IDocumentWidget>
adapter: WidgetAdapter<IDocumentWidget>,
collapse = true
): JSX.Element[] {
return document.ancestry.map((document: VirtualDocument) => {
if (!document.parent) {
Expand All @@ -16,7 +17,18 @@ export function get_breadcrumbs(
) {
path = path.slice(0, -document.file_extension.length - 1);
}
return <span key={document.uri}>{path}</span>;
const full_path = path;
if (collapse) {
let parts = path.split('/');
if (parts.length > 2) {
path = parts[0] + '/.../' + parts[parts.length - 1];
}
}
return (
<span key={document.uri} title={full_path}>
{path}
</span>
);
}
if (!document.virtual_lines.size) {
return <span key={document.uri}>Empty document</span>;
Expand Down

0 comments on commit d6f836e

Please sign in to comment.