Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools] Add column number to viewSourceLineFunction #24814

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/react-devtools-extensions/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ function createPanelIfReactLoaded() {
}
};

const viewSourceLineFunction = (url, line) => {
chrome.devtools.panels.openResource(url, line);
const viewUrlSourceFunction = (url, line, col) => {
chrome.devtools.panels.openResource(url, line, col);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, are you sure this works? The API docs says the 3rd parameter is callback, not column https://developer.chrome.com/docs/extensions/reference/devtools_panels/#method-openResource

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it does. The API for chrome.devtools.panels.openResource isn't up to date. If you inspect the actual function it takes 4 arguments, one of which is the columm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

let debugIDCounter = 0;
Expand Down Expand Up @@ -385,7 +385,7 @@ function createPanelIfReactLoaded() {
warnIfUnsupportedVersionDetected: true,
viewAttributeSourceFunction,
viewElementSourceFunction,
viewSourceLineFunction,
viewUrlSourceFunction,
}),
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import {createContext} from 'react';

import type {ViewSourceLine} from 'react-devtools-shared/src/devtools/views/DevTools';
import type {ViewUrlSource} from 'react-devtools-shared/src/devtools/views/DevTools';

export type Context = {|
viewSourceLineFunction: ViewSourceLine | null,
viewUrlSourceFunction: ViewUrlSource | null,
|};

const ViewSourceContext = createContext<Context>(((null: any): Context));
Expand Down
10 changes: 5 additions & 5 deletions packages/react-devtools-shared/src/devtools/views/DevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type ViewElementSource = (
id: number,
inspectedElement: InspectedElement,
) => void;
export type ViewSourceLine = (url: string, row: number, column: number) => void;
export type ViewUrlSource = (url: string, row: number, column: number) => void;
export type ViewAttributeSource = (
id: number,
path: Array<string | number>,
Expand All @@ -79,7 +79,7 @@ export type Props = {|
warnIfUnsupportedVersionDetected?: boolean,
viewAttributeSourceFunction?: ?ViewAttributeSource,
viewElementSourceFunction?: ?ViewElementSource,
viewSourceLineFunction?: ?ViewSourceLine,
viewUrlSourceFunction?: ?ViewUrlSource,
readOnly?: boolean,
hideSettings?: boolean,
hideToggleErrorAction?: boolean,
Expand Down Expand Up @@ -139,7 +139,7 @@ export default function DevTools({
warnIfUnsupportedVersionDetected = false,
viewAttributeSourceFunction,
viewElementSourceFunction,
viewSourceLineFunction,
viewUrlSourceFunction,
readOnly,
hideSettings,
hideToggleErrorAction,
Expand Down Expand Up @@ -205,11 +205,11 @@ export default function DevTools({

const viewSource = useMemo(
() => ({
viewSourceLineFunction: viewSourceLineFunction || null,
viewUrlSourceFunction: viewUrlSourceFunction || null,
// todo(blakef): Add inspect(...) method here and remove viewElementSource
// to consolidate source code inspection.
}),
[viewSourceLineFunction],
[viewUrlSourceFunction],
);

const contextMenu = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type Props = {||};

export default function SidebarEventInfo(_: Props) {
const {profilingData, selectedCommitIndex} = useContext(ProfilerContext);
const {viewSourceLineFunction} = useContext(ViewSourceContext);
const {viewUrlSourceFunction} = useContext(ViewSourceContext);

const {stack} = useMemo(() => {
if (
Expand Down Expand Up @@ -55,8 +55,8 @@ export default function SidebarEventInfo(_: Props) {
const hasSource = source != null;

const onClick = () => {
if (viewSourceLineFunction != null && source != null) {
viewSourceLineFunction(...source);
if (viewUrlSourceFunction != null && source != null) {
viewUrlSourceFunction(...source);
}
};

Expand Down