www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14397] New: dmd: Provide full source range for compiler

https://issues.dlang.org/show_bug.cgi?id=14397

          Issue ID: 14397
           Summary: dmd: Provide full source range for compiler errors
                    [enhancement]
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bruno.do.medeiros+deebugz gmail.com

When a D source file has an error, only the line number is reported by the
compiler. So for example, with:
```
void func() {
  writelnxxx("Hello");
}
```
the compiler error message:
`test.d(2): Error: undefined identifier writelnxxx`

This is okay for command line usage, but when the compiler is invoked by
editors and IDEs, it would be an improvement if a full source range was
reported - that is, the start offset (line+column) of the error, and the end
offset (line+column).

The option -vcolumns prints the column of the start of the error... but that is
not very useful unless the end of the range is reported as well!

As an example, here's the error output from the Rust compiler for a similar
error:
```
src\main.rs:8:5: 8:15 error: macro undefined: 'printlnxxx!'
src\main.rs:8     printlnxxx!("Hello world");
                  ^~~~~~~~~~
```
Here, the Rust compiler provides "8:5" as the start of the error range and
"8:15" the end of the range. Reporting the error location as absolute character
offsets from the start of the file (as opposed to line+column), would also work
fine (a start offset and an end offset).

With this, IDEs and editors can present errors as squiggly lines in a source
editor. Example, see how "xxx" is underlined:

https://cloud.githubusercontent.com/assets/4324232/6976292/8f01c25c-d99f-11e4-9b35-db9d380d2bd3.png

As a sidenote, https://github.com/bruno-medeiros/DDT/ in particular already
supports this functionality, but it needs the compiler to report the full
source ranges.

--
Apr 02 2015