NAME
PLS::Parser::Document
DESCRIPTION
This is a class that represents a text document. It has methods for parsing and manipulating the document using PPI and PPR.
METHODS
new
This creates a new PLS::Parser::Document object. It takes named parameters.
Either uri
or path
must be passed.
line
with a line number may be passed, which indicates that only one line of the document should be parsed. This greatly enhances performance for completion items.
set_index
This sets the PLS::Parser::Index object to be used by all PLS::Parser::Document objects.
get_index
This gets the PLS::Parser::Index object to use. It will set it for other objects to use if it does not already exist.
go_to_definition
This finds the definition of a symbol located at a given line and column number.
find_current_list
This finds the nearest list structure that surrounds the current column on the current line. This is useful for finding which parameter the cursor is on when calling a function.
go_to_definition_of_closest_subroutine
Given a list of elements, this finds the closest subroutine call to the current line and column.
search_elements_for_definition
This tries to find the definition in a list of elements, and returns the first definition found.
pod_link
This determines if the line and column are within a POD L<> code, and returns the contents of the link if so.
find_pod
This attempts to find POD for the symbol at the given location.
find_external_subroutine
This attempts to find the location of a subroutine inside an external module, by name.
find_external_package
This attempts to find the location of an external package by name.
go_to_variable_definition
This finds the definition of a variable.
This probably only works correctly for my
, local
, and state
variables, but may also work for our
variables as long as they are in the same file.
open_file
This adds a file and its text to a list of open files.
open_files
This provides a list of names of files that are currently open.
update_file
This patches an open file in memory to keep it synched with the actual file in the editor.
close_file
This removes a file from the list of open files.
get_subroutines
This gets a list of all subroutines in a document.
get_constants
This gets a list of all constants in a document.
Only constants declared with use constant
are found.
get_packages
This gets a list of all packages in a document.
get_variable_statements
This gets a list of all variable statements in a document. A variable statement is a statement which declares one or more variables.
get_full_text
This returns a SCALAR reference of the in-memory text of the current document.
get_variables_fast
This gets a list of all variables in the current document. It uses PPR to do so, which is faster than PPI, but only provides a list of strings.
get_packages_fast
This gets a list of all packages in the current document. It uses PPR to do so, which is faster than PPI, but only provides a list of strings.
get_subroutines_fast
This gets a list of all subroutines in the current document. It uses PPR to do so, which is faster than PPI, but only provides a list of strings.
get_constants_fast
This gets a list of all constants in the current document. It uses PPR to do so, which is faster than PPI, but only provides a list of strings.
This only finds constants declared with use constant
.
format_range
This formats a range of text in the document using perltidy.
format
This formats the entire document using perltidy.
_ppi_location
This converts an LSP 0-indexed location to a PPI 1-indexed location.
text_from_uri
This returns a SCALAR reference to the text of a particular URI.
_get_ppi_document
This creates a PPI::Document object for a document. It will return an PPI::Document from memory if the file has not changed since it was last parsed.
_is_constant
Determines if a PPI element is a constant.
find_word_under_cursor
Gets information about the current word under the cursor. Returns a four-element list:
- The range where the word is located
- A boolean indicating whether the word is before an arrow (->) or not.
- The name of the package where the word is located
- The word under the cursor to be used as a filter for searching
get_list_index
Gets the index within a list where a cursor is.
This is useful for determining which function parameter the cursor is on within a function call.
sort_imports
This sorts the imports within a file. The order is:
use strict
anduse warnings
use parent
anduse base
- Other pragmas (excluding
use constant
) - Core and external imports
- Internal imports (from the current project)
- Constants (
use constant
)
_sort_imports
Determines the sorting of two imports within a block of imports.
_pad_imports
Adds newlines to pad the various import sections from each other and from the rest of the document.
_split_lines
Splits a document into lines using $/
as the separator.