Skip to content

CodeDocument#

Base document object for any code that Knut can parse. More...

import Script

Properties#

Inherited properties: TextDocument properties

Methods#

Name
Symbol findSymbol(string name, int options = TextDocument.NoFindFlags)
string hover()
array<QueryMatch> query(string query)
QueryMatch queryFirst(string query)
array<QueryMatch> queryInRange(RangeMark range, string query)
selectSymbol(string name, int options = TextDocument.NoFindFlags)
Symbol symbolUnderCursor()
array<Symbol> symbols()

Inherited methods: TextDocument methods

Detailed Description#

Knut uses Tree-sitter to parse the code and provide additional information about it. For a better user experience, the Knut GUI also uses a Language server (LSP), if available. For each language that Knut can work with, this class should be subclassed to provide language-specific functionality.

This class provides the language-independent basis of integration with Tree-sitter and the LSP.

Method Documentation#

Symbol findSymbol(string name, int options = TextDocument.NoFindFlags)#

Finds a symbol based on its name, using different find options.

  • TextDocument.FindCaseSensitively: match case
  • TextDocument.FindWholeWords: match only fully qualified symbol
  • TextDocument.FindRegexp: use a regexp

Note that the returned Symbol pointer is only valid until the document it originates from is deconstructed.

string hover()#

Returns information about the symbol at the current cursor position. The result of this call is a plain string that may be formatted in Markdown.

array<QueryMatch> query(string query)#

Runs the given Tree-sitter query and returns the list of matches.

The query is using Tree-sitter queries.

Also see: Tree-sitter in Knut

QueryMatch queryFirst(string query)#

Runs the given Tree-sitter query and returns the first match. If no match can be found an empty match will be returned.

This can be a lot faster than query if you only need the first match.

The query is using Tree-sitter queries.

Also see: Tree-sitter in Knut Core::QueryMatchList CodeDocument::query(const QString &query)

array<QueryMatch> queryInRange(RangeMark range, string query)#

Searches for the given query, but only in the provided range.

selectSymbol(string name, int options = TextDocument.NoFindFlags)#

Selects a symbol based on its name, using different find options.

  • TextDocument.FindCaseSensitively: match case
  • TextDocument.FindWholeWords: match only fully qualified symbol
  • TextDocument.FindRegexp: use a regexp

If no symbols are found, do nothing.

Symbol symbolUnderCursor()#

Returns the symbol that's at the current cursor position.

This function may return symbols that are not returned by the symbols() or currentSymbol() function, as these only return high-level symbols, like classes and functions, but not symbols within functions. symbolUnderCursor() can however return these Symbols.

array<Symbol> symbols()#

Returns the list of symbols in the current document.

Note that the returned Symbol pointers are only valid until the document they originate from is deconstructed.