@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.
@@ -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.237",
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": "9d62964ad983602ecc905f578af1b8947501ab59"
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 = ({content, language, renderer}: HighlighterProps): JSX.Element => {
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('text-right', charsToWidth(content.split('\n').length.toString().length))}
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>
@@ -65,6 +65,7 @@ export const SourceView = React.memo(function SourceView({
65
65
 
66
66
  return (
67
67
  <Highlighter
68
+ file={sourceFileName as string}
68
69
  content={data.source}
69
70
  renderer={profileAwareRenderer(cumulative, flat, total, filtered)}
70
71
  />