Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Add more position conversion functions #1223

Merged
merged 1 commit into from
Jun 26, 2019
Merged

Conversation

rocky
Copy link

@rocky rocky commented Jun 19, 2019

  • type LineColPosition,
  • type LineColRange,
  • function lineColPositionFromOffset
  • function srcToLineColumnRange

And associated tests for these.

To discuss:

One thing I would like to see is clarification of things in remix-astWalker/src/types.ts like Location.

Here it means the interpretation of a solc-style AST-field src. I think then that should be made explicit like solcLocation.

Although I personally like the solcLocation for its compactness, more common is a line/column based range. And here there are a couple of variations depending on whether columns and lines start at 0 or 1.

Since I am using this stuff in a LSP oriented way, I have adopted their convention of both lines and columns starting at 1. Personally I am okay with adding more kinds of things for other ways to represent a location.

@rocky rocky changed the title Add more position conversion functions [WIP] Add more position conversion functions Jun 19, 2019
@@ -1,28 +1,60 @@
import { isAstNode, AstWalker } from './astWalker';
import { AstNode, Location } from "./types";
import { AstNode, LineColPosition, LineColRange, Location } from "./types";
const util = require("remix-lib").util;
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we use here the import ... from ?

Copy link
Author

Choose a reason for hiding this comment

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

Sure. Note though this was not as easy as just changing that line...

remix-lib is not in typescript so there are not types for that and I could not find a @types/remix-lib. Rather than undertake writing such a module, I opted for starting one of the one function I need in remix-astWalker. I am new to this stuff, so I don't know if this was done properly.

* @returns {LineColPosition}
*/
export function lineColPositionFromOffset(offset: number, lineBreaks: Array<number>): LineColPosition {
let line: number = util.findLowerBound(offset, lineBreaks);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we are basically moving this from

, which seems needed. But we can't keep both code, we should deprecate the one in remix-lib

Copy link
Author

Choose a reason for hiding this comment

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

I am assuming this is just a comment. If there was some action I should take here, let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think once remix-astWalker gets a bit mature, we can start removing existing codes we are copying/migrating from.

Copy link
Author

@rocky rocky Jun 26, 2019

Choose a reason for hiding this comment

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

Would love to see that and will help to make sure this is integrated to your atom plugin. See also #1224, #1225, #1226, #1227 which @yann300 asked me to log as issues.

Also although I haven't logged as an issue, the whole walker function could probably be async which might improve performance. I haven't logged that as an issue though.

#1230 is not really related but it is a big annoyance in vscode because it brings in keccak which vscode barfs on badly. (I need to isolate what's up there and report to Microsoft. I recall it has been reported in the past, but not isolated.)

Copy link
Author

Choose a reason for hiding this comment

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

Also I should say that I am sure there are lots of opportunities for making things efficient. But first we should have the basic functionality working, and right now in the plain walk routine I don't think that is the case. (This is a little bit an artifact of the current solc AST design which I believe will be documented better in the future.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think once remix-astWalker gets a bit mature, we can start removing existing codes we are copying/migrating from.

sounds good

- type LineColPosition,
- type LineColRange,
- function lineColPositionFromOffset
- function srcToLineColumnRange

And associated tests for these
@yann300 yann300 merged commit 57ebf16 into ethereum:master Jun 26, 2019
@rocky rocky changed the title [WIP] Add more position conversion functions Add more position conversion functions Jul 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants