Class ScriptFile
Contains the details and contents of an open script file.
Inheritance
Namespace:Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
Assembly:Microsoft.SqlTools.ServiceLayer.dll
Syntax
public class ScriptFile
Constructors
| Improve this Doc View SourceScriptFile()
Add a default constructor for testing
Declaration
public ScriptFile()
ScriptFile(String, String, TextReader)
Creates a new ScriptFile instance by reading file contents from the given TextReader.
Declaration
public ScriptFile(string filePath, string clientFilePath, TextReader textReader)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | The path at which the script file resides. |
System.String | clientFilePath | The path which the client uses to identify the file. |
System.IO.TextReader | textReader | The TextReader to use for reading the file's contents. |
ScriptFile(String, String, String)
Creates a new ScriptFile instance with the specified file contents.
Declaration
public ScriptFile(string filePath, string clientFilePath, string initialBuffer)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | The path at which the script file resides. |
System.String | clientFilePath | The path which the client uses to identify the file. |
System.String | initialBuffer | The initial contents of the script file. |
Properties
| Improve this Doc View SourceClientFilePath
Gets or sets the path which the editor client uses to identify this file. Setter for testing purposes only virtual to allow mocking.
Declaration
public virtual string ClientFilePath { get; }
Type | Description |
---|---|
System.String |
Contents
Gets or sets a string containing the full contents of the file. Setter for testing purposes only
Declaration
public virtual string Contents { get; set; }
Type | Description |
---|---|
System.String |
FilePath
Gets the path at which this file resides.
Declaration
public string FilePath { get; }
Type | Description |
---|---|
System.String |
FileRange
Gets a BufferRange that represents the entire content range of the file.
Declaration
public BufferRange FileRange { get; }
Type | Description |
---|---|
BufferRange |
Id
Gets a unique string that identifies this file. At this time, this property returns a normalized version of the value stored in the FilePath property.
Declaration
public string Id { get; }
Type | Description |
---|---|
System.String |
IsInMemory
Gets a boolean that determines whether this file is in-memory or not (either unsaved or non-file content).
Declaration
public bool IsInMemory { get; }
Type | Description |
---|---|
System.Boolean |
SyntaxMarkers
Gets the list of syntax markers found by parsing this file's contents.
Declaration
public ScriptFileMarker[] SyntaxMarkers { get; }
Type | Description |
---|---|
ScriptFileMarker[] |
Methods
| Improve this Doc View SourceApplyChange(FileChange)
Applies the provided FileChange to the file's contents
Declaration
public void ApplyChange(FileChange fileChange)
Parameters
Type | Name | Description |
---|---|---|
FileChange | fileChange | The FileChange to apply to the file's contents. |
CalculatePosition(BufferPosition, Int32, Int32)
Calculates a FilePosition relative to a starting BufferPosition using the given 1-based line and column offset.
Declaration
public FilePosition CalculatePosition(BufferPosition originalPosition, int lineOffset, int columnOffset)
Parameters
Type | Name | Description |
---|---|---|
BufferPosition | originalPosition | The original BufferPosition from which an new position should be calculated. |
System.Int32 | lineOffset | The 1-based line offset added to the original position in this file. |
System.Int32 | columnOffset | The 1-based column offset added to the original position in this file. |
Returns
Type | Description |
---|---|
FilePosition | A new FilePosition instance with the resulting line and column number. |
GetLine(Int32)
Gets a line from the file's contents.
Declaration
public string GetLine(int lineNumber)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | lineNumber | The 1-based line number in the file. |
Returns
Type | Description |
---|---|
System.String | The complete line at the given line number. |
GetLinesInRange(BufferRange)
Gets a range of lines from the file's contents. Virtual method to allow for mocking.
Declaration
public virtual string[] GetLinesInRange(BufferRange bufferRange)
Parameters
Type | Name | Description |
---|---|---|
BufferRange | bufferRange | The buffer range from which lines will be extracted. |
Returns
Type | Description |
---|---|
System.String[] | An array of strings from the specified range of the file. |
GetOffsetAtPosition(Int32, Int32)
Calculates the zero-based character offset of a given line and column position in the file.
Declaration
public int GetOffsetAtPosition(int lineNumber, int columnNumber)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | lineNumber | The 1-based line number from which the offset is calculated. |
System.Int32 | columnNumber | The 1-based column number from which the offset is calculated. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based offset for the given file position. |
GetPositionAtOffset(Int32)
Calculates the 1-based line and column number position based on the given buffer offset.
Declaration
public BufferPosition GetPositionAtOffset(int bufferOffset)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | bufferOffset | The buffer offset to convert. |
Returns
Type | Description |
---|---|
BufferPosition | A new BufferPosition containing the position of the offset. |
GetRangeBetweenOffsets(Int32, Int32)
Calculates the 1-based line and column number range based on the given start and end buffer offsets.
Declaration
public BufferRange GetRangeBetweenOffsets(int startOffset, int endOffset)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startOffset | The start offset of the range. |
System.Int32 | endOffset | The end offset of the range. |
Returns
Type | Description |
---|---|
BufferRange | A new BufferRange containing the positions in the offset range. |
SetFileContents(String)
Set the script files contents
Declaration
public void SetFileContents(string fileContents)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileContents |
ValidatePosition(BufferPosition)
Throws ArgumentOutOfRangeException if the given position is outside of the file's buffer extents.
Declaration
public void ValidatePosition(BufferPosition bufferPosition)
Parameters
Type | Name | Description |
---|---|---|
BufferPosition | bufferPosition | The position in the buffer to be validated. |
ValidatePosition(Int32, Int32)
Throws ArgumentOutOfRangeException if the given position is outside of the file's buffer extents.
Declaration
public void ValidatePosition(int line, int column)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | line | The 1-based line to be validated. |
System.Int32 | column | The 1-based column to be validated. |