match method
Compute the match between a document {@link DocumentSelectorselector} and a document. Values greater than zero mean the selector matches the document.
A match is computed according to these rules:
- When {@linkcode DocumentSelector} is an array, compute the match for each contained
DocumentFilter
or language identifier and take the maximum value. - A string will be desugared to become the
language
-part of a {@linkcode DocumentFilter}, so"fooLang"
is like{ language: "fooLang" }
. - A {@linkcode DocumentFilter} will be matched against the document by comparing its parts with the document. The following rules apply:
- When the
DocumentFilter
is empty ({}
) the result is0
- When
scheme
,language
,pattern
, ornotebook
are defined but one doesn't match, the result is0
- Matching against
*
gives a score of5
, matching via equality or via a glob-pattern gives a score of10
- The result is the maximum value of each match
- When the
Samples:
// default document from disk (file-scheme)
doc.uri; //'file:///my/file.js'
doc.languageId; // 'javascript'
match('javascript', doc); // 10;
match({ language: 'javascript' }, doc); // 10;
match({ language: 'javascript', scheme: 'file' }, doc); // 10;
match('*', doc); // 5
match('fooLang', doc); // 0
match(['fooLang', '*'], doc); // 5
// virtual document, e.g. from git-index
doc.uri; // 'git:/my/file.js'
doc.languageId; // 'javascript'
match('javascript', doc); // 10;
match({ language: 'javascript', scheme: 'git' }, doc); // 10;
match('*', doc); // 5
// notebook cell document
doc.uri; // `vscode-notebook-cell:///my/notebook.ipynb#gl65s2pmha`;
doc.languageId; // 'python'
match({ notebookType: 'jupyter-notebook' }, doc) // 10
match({ notebookType: 'fooNotebook', language: 'python' }, doc) // 0
match({ language: 'python' }, doc) // 10
match({ notebookType: '*' }, doc) // 5
Implementation
_i2.num match(
_i2.Object selector,
_i3.TextDocument document,
) =>
_i4.callMethod(
this,
'match',
[
selector,
document,
],
);