Proposal to expose Position information used for error messages in JSonReader in public API
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
Thanks for maintaining this library!
# Problem solved by the feature
* Many projects use JSON notation for their DSL's syntax
* Reusing Gson implies high quality and compatible parsing for those DSLs
* IDE support for DSLs requires position information (offset/length, start line/column, end line/column
* For example to create Language Servers for the LSP for the given (embedded) DSLs
# Feature description
Proposal to expose the following fields of JsonReader:
```
private int pos = 0;
private int lineNumber = 0;
private int lineStart = 0;
```
With these public methods:
```
public int getPosition() {
return pos;
}
public int getLineNumber() {
return lineNumber + 1; // posix has the first line at 1
}
public int getColumnNumber() {
return pos - lineStart; // posix has columns start at 0
}
```
Using these methods just before `beginObject()` and just after `endObject()` you get an accurate measurement
of the span of every object in the character stream.
# Alternatives / workarounds
* We currently use the reflection API to access these fields in the usethesource/rascal meta-programming project.
* That seems to work fine, but it's not as nice as it could be :-)
Contributor guide
Research direction
Start by reading JsonReader and the existing handling of pos, lineNumber, and lineStart. Review how these values behave immediately before beginObject() and after endObject(), then determine how the requested public accessors should expose position, line, and column data. Done means callers can obtain accurate object-span information without reflection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100