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

start and end for location and zero base #290

Closed
axetroy opened this issue Aug 29, 2020 · 3 comments · Fixed by #298
Closed

start and end for location and zero base #290

axetroy opened this issue Aug 29, 2020 · 3 comments · Fixed by #298

Comments

@axetroy
Copy link

axetroy commented Aug 29, 2020

before:

{
 "diagnostics": [
    {
     "location": {
        "filename": "/path/to/file/mod.ts",
         "line": 1,
         "col": 0,
      },
     "message": "`debugger` statement is not allowed",
     "code": "no-debugger",
     "line_src": "debugger;",
     "snippet_length": 9,
    },
  ],
 "errors": [],
}

after:

{
 "diagnostics": [
    {
	  "file": "/path/to/file/mod.ts",
      "location": {
	  	"start": {
          "line": 0,
           "col": 0
        },
		"end": {
          "line": 0,
          "col": 8
        }
      },
      "message": "`debugger` statement is not allowed",
      "code": "no-debugger",
      "line_src": "debugger;",
      "snippet_length": 9,
    },
  ],
  "errors": [],
}
@bartlomieju
Copy link
Member

Thanks @axetroy I actually intended to implement this, with recent changes to Location struct.

snippet_length and line_src fields will be removed

@axetroy
Copy link
Author

axetroy commented Aug 29, 2020

Good to hear. Here is the implementation of vscode. this may help

Location

/**
 * A range in a text document expressed as (zero-based) start and end positions.
 *
 * If you want to specify a range that contains a line including the line ending
 * character(s) then use an end position denoting the start of the next line.
 * For example:
 * ```ts
 * {
 *     start: { line: 5, character: 23 }
 *     end : { line 6, character : 0 }
 * }
 * ```
 */
export interface Range {
    /**
     * The range's start position
     */
    start: Position;
    /**
     * The range's end position.
     */
    end: Position;
}

/**
 * Position in a text document expressed as zero-based line and character offset.
 * The offsets are based on a UTF-16 string representation. So a string of the form
 * `a𐐀b` the character offset of the character `a` is 0, the character offset of `𐐀`
 * is 1 and the character offset of b is 3 since `𐐀` is represented using two code
 * units in UTF-16.
 *
 * Positions are line end character agnostic. So you can not specify a position that
 * denotes `\r|\n` or `\n|` where `|` represents the character offset.
 */
export interface Position {
    /**
     * Line position in a document (zero-based).
     * If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.
     * If a line number is negative, it defaults to 0.
     */
    line: number;
    /**
     * Character offset on a line in a document (zero-based). Assuming that the line is
     * represented as a string, the `character` value represents the gap between the
     * `character` and `character + 1`.
     *
     * If the character value is greater than the line length it defaults back to the
     * line length.
     * If a line number is negative, it defaults to 0.
     */
    character: number;
}

Diagnostic

/**
 * Represents a diagnostic, such as a compiler error or warning. Diagnostic objects
 * are only valid in the scope of a resource.
 */
export interface Diagnostic {
    /**
     * The range at which the message applies
     */
    range: Range;
    /**
     * The diagnostic's severity. Can be omitted. If omitted it is up to the
     * client to interpret diagnostics as error, warning, info or hint.
     */
    severity?: DiagnosticSeverity;
    /**
     * The diagnostic's code, which usually appear in the user interface.
     */
    code?: number | string;
    /**
     * A human-readable string describing the source of this
     * diagnostic, e.g. 'typescript' or 'super lint'. It usually
     * appears in the user interface.
     */
    source?: string;
    /**
     * The diagnostic's message. It usually appears in the user interface
     */
    message: string;
    /**
     * Additional metadata about the diagnostic.
     */
    tags?: DiagnosticTag[];
    /**
     * An array of related diagnostic information, e.g. when symbol-names within
     * a scope collide all definitions can be marked via this property.
     */
    relatedInformation?: DiagnosticRelatedInformation[];
}

@bartlomieju
Copy link
Member

@axetroy looking at Diagnostic interface I think we'll only use range, code and message. Can you fill out the rest of the values in the extension?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants