Skip to content

Commit d6f836e

Browse files
authored
Merge pull request #524 from krassowski/collapse_long_paths
Collapse paths for files deep in subfolders
2 parents c3e90ec + fd0fe88 commit d6f836e

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- the completer now uses `filterText` and `sortText` if available to better filter and sort completions ([#520], [#523])
1111
- completer `suppressInvokeIn` setting was removed; `suppressContinuousHintingIn` and `suppressTriggerCharacterIn` settings were added ([#521])
1212
- `suppressContinuousHintingIn` by default includes `def` to improve the experience when writing function names ([#521])
13+
- long file paths are now collapsed if composed of more than two segments to avoid status popover and diagnostics panel getting too wide ([#524])
1314

1415
- bug fixes:
1516
- user-invoked completion in strings works again ([#521])
@@ -21,6 +22,7 @@
2122
[#521]: https://github.com/krassowski/jupyterlab-lsp/pull/521
2223
[#522]: https://github.com/krassowski/jupyterlab-lsp/pull/522
2324
[#523]: https://github.com/krassowski/jupyterlab-lsp/pull/523
25+
[#524]: https://github.com/krassowski/jupyterlab-lsp/pull/524
2426

2527
### `@krassowski/jupyterlab-lsp 3.3.1` (2020-02-07)
2628

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { get_breadcrumbs } from './utils';
2+
import { VirtualDocument } from '../virtual/document';
3+
import { WidgetAdapter } from '../adapters/adapter';
4+
import { IDocumentWidget } from '@jupyterlab/docregistry';
5+
6+
function create_dummy_document(options: Partial<VirtualDocument.IOptions>) {
7+
return new VirtualDocument({
8+
language: 'python',
9+
foreign_code_extractors: {},
10+
overrides_registry: {},
11+
path: 'Untitled.ipynb.py',
12+
file_extension: 'py',
13+
has_lsp_supported_file: false,
14+
...options
15+
});
16+
}
17+
18+
describe('get_breadcrumbs', () => {
19+
it('should collapse long paths', () => {
20+
let document = create_dummy_document({
21+
path: 'dir1/dir2/Test.ipynb'
22+
});
23+
let breadcrumbs = get_breadcrumbs(document, {
24+
has_multiple_editors: false
25+
} as WidgetAdapter<IDocumentWidget>);
26+
expect(breadcrumbs[0].props['title']).toBe('dir1/dir2/Test.ipynb');
27+
expect(breadcrumbs[0].props['children']).toBe('dir1/.../Test.ipynb');
28+
});
29+
30+
it('should trim the extra filename suffix for files created out of notebooks', () => {
31+
let document = create_dummy_document({
32+
path: 'Test.ipynb.py',
33+
file_extension: 'py',
34+
has_lsp_supported_file: false
35+
});
36+
let breadcrumbs = get_breadcrumbs(document, {
37+
has_multiple_editors: false
38+
} as WidgetAdapter<IDocumentWidget>);
39+
expect(breadcrumbs[0].props['children']).toBe('Test.ipynb');
40+
});
41+
42+
it('should not trim the filename suffix for standalone files', () => {
43+
let document = create_dummy_document({
44+
path: 'test.py',
45+
file_extension: 'py',
46+
has_lsp_supported_file: true
47+
});
48+
let breadcrumbs = get_breadcrumbs(document, {
49+
has_multiple_editors: false
50+
} as WidgetAdapter<IDocumentWidget>);
51+
expect(breadcrumbs[0].props['children']).toBe('test.py');
52+
});
53+
});

packages/jupyterlab-lsp/src/components/utils.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import React from 'react';
55

66
export function get_breadcrumbs(
77
document: VirtualDocument,
8-
adapter: WidgetAdapter<IDocumentWidget>
8+
adapter: WidgetAdapter<IDocumentWidget>,
9+
collapse = true
910
): JSX.Element[] {
1011
return document.ancestry.map((document: VirtualDocument) => {
1112
if (!document.parent) {
@@ -16,7 +17,18 @@ export function get_breadcrumbs(
1617
) {
1718
path = path.slice(0, -document.file_extension.length - 1);
1819
}
19-
return <span key={document.uri}>{path}</span>;
20+
const full_path = path;
21+
if (collapse) {
22+
let parts = path.split('/');
23+
if (parts.length > 2) {
24+
path = parts[0] + '/.../' + parts[parts.length - 1];
25+
}
26+
}
27+
return (
28+
<span key={document.uri} title={full_path}>
29+
{path}
30+
</span>
31+
);
2032
}
2133
if (!document.virtual_lines.size) {
2234
return <span key={document.uri}>Empty document</span>;

0 commit comments

Comments
 (0)