|
4 | 4 |
|
5 | 5 | // @flow |
6 | 6 | import { endTruncateStr } from "./utils"; |
7 | | -import { isPretty, getSourcePath } from "./source"; |
| 7 | +import { isPretty, getFilename } from "./source"; |
8 | 8 |
|
9 | 9 | import type { Location as BabelLocation } from "@babel/types"; |
10 | | -import type { SourcesMap } from "../reducers/sources"; |
11 | 10 | import type { Symbols } from "../reducers/ast"; |
12 | 11 | import type { QuickOpenType } from "../reducers/quick-open"; |
13 | 12 | import type { SymbolDeclaration } from "../workers/parser"; |
| 13 | +import type { RelativeSource } from "../selectors/getRelativeSources"; |
14 | 14 |
|
15 | 15 | export const MODIFIERS = { |
16 | 16 | "@": "functions", |
@@ -49,6 +49,19 @@ export function parseLineColumn(query: string) { |
49 | 49 | } |
50 | 50 | } |
51 | 51 |
|
| 52 | +export function formatSourcesForList(source: RelativeSource) { |
| 53 | + const title = getFilename(source); |
| 54 | + const subtitle = endTruncateStr(source.relativeUrl, 100); |
| 55 | + |
| 56 | + return { |
| 57 | + value: source.relativeUrl, |
| 58 | + title, |
| 59 | + subtitle, |
| 60 | + id: source.id, |
| 61 | + url: source.url |
| 62 | + }; |
| 63 | +} |
| 64 | + |
52 | 65 | export type QuickOpenResult = {| |
53 | 66 | id: string, |
54 | 67 | value: string, |
@@ -106,25 +119,11 @@ export function formatShortcutResults(): Array<QuickOpenResult> { |
106 | 119 | ]; |
107 | 120 | } |
108 | 121 |
|
109 | | -export function formatSources(sources: SourcesMap): Array<QuickOpenResult> { |
| 122 | +export function formatSources( |
| 123 | + sources: RelativeSource[] |
| 124 | +): Array<QuickOpenResult> { |
110 | 125 | return sources |
111 | | - .valueSeq() |
112 | 126 | .filter(source => !isPretty(source)) |
113 | | - .map(source => { |
114 | | - const sourcePath = getSourcePath(source.url); |
115 | | - return { |
116 | | - value: sourcePath, |
117 | | - title: sourcePath |
118 | | - .split("/") |
119 | | - .pop() |
120 | | - .split("?")[0], |
121 | | - subtitle: endTruncateStr(sourcePath, 100) |
122 | | - .replace(sourcePath.split("/").pop(), "") |
123 | | - .slice(1, -1), |
124 | | - id: source.id, |
125 | | - url: source.url |
126 | | - }; |
127 | | - }) |
128 | | - .filter(({ value }) => value != "") |
129 | | - .toJS(); |
| 127 | + .map(source => formatSourcesForList(source)) |
| 128 | + .filter(({ value }) => value != ""); |
130 | 129 | } |
0 commit comments