@parca/profile 0.16.237 → 0.16.238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/MetricsGraph/index.js +4 -4
- package/dist/SourceView/Highlighter.d.ts +2 -2
- package/dist/SourceView/Highlighter.js +9 -3
- package/dist/SourceView/index.js +1 -1
- package/dist/SourceView/lang-detector/ext-to-lang.json +800 -0
- package/dist/SourceView/lang-detector/index.d.ts +1 -0
- package/dist/SourceView/lang-detector/index.js +29 -0
- package/package.json +2 -2
- package/src/MetricsGraph/index.tsx +5 -5
- package/src/SourceView/Highlighter.tsx +16 -4
- package/src/SourceView/index.tsx +1 -0
- package/src/SourceView/lang-detector/ext-to-lang.json +800 -0
- package/src/SourceView/lang-detector/index.ts +33 -0
- package/typings.d.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const langaugeFromFile: (file: string) => string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2022 The Parca Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import * as hljsLangs from 'react-syntax-highlighter/dist/esm/languages/hljs';
|
|
14
|
+
import _extLangMap from './ext-to-lang.json';
|
|
15
|
+
const extLangMap = _extLangMap;
|
|
16
|
+
export const langaugeFromFile = (file) => {
|
|
17
|
+
const extension = file.split('.').pop() ?? '';
|
|
18
|
+
if (extLangMap[extension] == null) {
|
|
19
|
+
return 'text';
|
|
20
|
+
}
|
|
21
|
+
const langs = extLangMap[extension];
|
|
22
|
+
for (const lang of langs) {
|
|
23
|
+
// eslint-disable-next-line import/namespace
|
|
24
|
+
if (hljsLangs[lang] != null) {
|
|
25
|
+
return lang;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return 'text';
|
|
29
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parca/profile",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.238",
|
|
4
4
|
"description": "Profile viewing libraries",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@parca/client": "^0.16.86",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"access": "public",
|
|
50
50
|
"registry": "https://registry.npmjs.org/"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "5372bb39e5aabffc1884b6141803f173e1a2a490"
|
|
53
53
|
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
|
|
14
|
-
import React, {useRef, useState} from 'react';
|
|
14
|
+
import React, {Fragment, useRef, useState} from 'react';
|
|
15
15
|
|
|
16
16
|
import * as d3 from 'd3';
|
|
17
17
|
import {pointer} from 'd3-selection';
|
|
@@ -408,7 +408,7 @@ export const RawMetricsGraph = ({
|
|
|
408
408
|
<g transform={`translate(${margin}, ${margin})`}>
|
|
409
409
|
<g className="y axis" textAnchor="end" fontSize="10" fill="none">
|
|
410
410
|
{yScale.ticks(5).map((d, i) => (
|
|
411
|
-
|
|
411
|
+
<Fragment key={`${i.toString()}-${d.toString()}`}>
|
|
412
412
|
<g
|
|
413
413
|
key={`tick-${i}`}
|
|
414
414
|
className="tick"
|
|
@@ -429,7 +429,7 @@ export const RawMetricsGraph = ({
|
|
|
429
429
|
y2={yScale(d)}
|
|
430
430
|
/>
|
|
431
431
|
</g>
|
|
432
|
-
|
|
432
|
+
</Fragment>
|
|
433
433
|
))}
|
|
434
434
|
<line
|
|
435
435
|
className="stroke-gray-300 dark:stroke-gray-500"
|
|
@@ -454,7 +454,7 @@ export const RawMetricsGraph = ({
|
|
|
454
454
|
transform={`translate(0,${height - margin})`}
|
|
455
455
|
>
|
|
456
456
|
{xScale.ticks(5).map((d, i) => (
|
|
457
|
-
|
|
457
|
+
<Fragment key={`${i.toString()}-${d.toString()}`}>
|
|
458
458
|
<g
|
|
459
459
|
key={`tick-${i}`}
|
|
460
460
|
className="tick"
|
|
@@ -475,7 +475,7 @@ export const RawMetricsGraph = ({
|
|
|
475
475
|
y2={-height + margin}
|
|
476
476
|
/>
|
|
477
477
|
</g>
|
|
478
|
-
|
|
478
|
+
</Fragment>
|
|
479
479
|
))}
|
|
480
480
|
<line
|
|
481
481
|
className="stroke-gray-300 dark:stroke-gray-500"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
|
|
14
|
-
import {useId} from 'react';
|
|
14
|
+
import {useId, useMemo} from 'react';
|
|
15
15
|
|
|
16
16
|
import {Vector} from 'apache-arrow';
|
|
17
17
|
import cx from 'classnames';
|
|
@@ -25,6 +25,7 @@ import {selectDarkMode, useAppSelector} from '@parca/store';
|
|
|
25
25
|
|
|
26
26
|
import {useProfileViewContext} from '../ProfileView/ProfileViewContext';
|
|
27
27
|
import {LineNo} from './LineNo';
|
|
28
|
+
import {langaugeFromFile} from './lang-detector';
|
|
28
29
|
|
|
29
30
|
interface RendererProps {
|
|
30
31
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -36,8 +37,8 @@ interface RendererProps {
|
|
|
36
37
|
type Renderer = ({rows, stylesheet, useInlineStyles}: RendererProps) => JSX.Element;
|
|
37
38
|
|
|
38
39
|
interface HighlighterProps {
|
|
40
|
+
file: string;
|
|
39
41
|
content: string;
|
|
40
|
-
language?: string;
|
|
41
42
|
renderer?: Renderer;
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -168,14 +169,25 @@ export const profileAwareRenderer = (
|
|
|
168
169
|
};
|
|
169
170
|
};
|
|
170
171
|
|
|
171
|
-
export const Highlighter = ({
|
|
172
|
+
export const Highlighter = ({file, content, renderer}: HighlighterProps): JSX.Element => {
|
|
172
173
|
const isDarkMode = useAppSelector(selectDarkMode);
|
|
174
|
+
const language = useMemo(() => langaugeFromFile(file), [file]);
|
|
173
175
|
|
|
174
176
|
return (
|
|
175
177
|
<div className="relative">
|
|
176
178
|
<div className="flex gap-2 text-xs">
|
|
177
179
|
<div
|
|
178
|
-
className={cx(
|
|
180
|
+
className={cx(
|
|
181
|
+
'text-right',
|
|
182
|
+
charsToWidth(
|
|
183
|
+
content
|
|
184
|
+
.split(
|
|
185
|
+
// prettier-ignore
|
|
186
|
+
'\n'
|
|
187
|
+
)
|
|
188
|
+
.length.toString().length
|
|
189
|
+
)
|
|
190
|
+
)}
|
|
179
191
|
>
|
|
180
192
|
Line
|
|
181
193
|
</div>
|
package/src/SourceView/index.tsx
CHANGED