File
A utility class to read files and interact with it to create ranges. This class is accessible by accessing the file
field on the main module.
Functions
fromPath constructor
File.fromPath( path: string, -- The path to this file name: string -- The name that this file should be given inside error messages) → File
Creates a new file by reading the contents of a file at a path.
fromString constructor
File.fromString( name: string, -- The name that this file should be given inside error messages content: string -- The content of this file) → File
Creates a new file from a string.
getContentForRange
File:getContentForRange( contentRange: FileRange -- The range of the content) → string? -- The content of the file for the range
Returns the content of the file for the range passed.
getLineRange
File:getLineRange( lineStart: number, -- The start line number lineEnd: number -- The end line number) → FileRange? -- The range of the lines
Returns the range created by the start of the first line and the end of the last line.
getLinesInRange
File:getLinesInRange( contentRange: FileRange -- The range of the content) → {line} -- The lines of the file for the range
Types
interface line { lineNum: number, -- The line number line: FileRange, -- The range of the line}
Returns the lines of the file for the range passed.
getNormalizedContentForRange
File:getNormalizedContentForRange( contentRange: FileRange -- The range of the content) → string? -- The content of the file for the range
Returns the content of the file for the range passed, with the indentation normalized (finds lowest indentation, and remove all preceding indentation).
getRange
File:getRange( startCharacter: number, -- The start character number endCharacter: number -- The end character number) → FileRange? -- The range of the characters
Returns the range of the character numbers passed.
getRangeForLine
File:getRangeForLine( line: number -- The line number) → FileRange? -- The range of the line
Returns the range of the line number passed.
positionToLine
File:positionToLine( position: number -- The position to convert to a line number) → (number?, -- The line numberFileRange? -- The range of the line)
Given a position as a number, returns the line number and the line range of the line this position is on.