Is there a native api in vscode to match a document file by a glob?

Viewed 106

I have a vscode.TextDocument and want to check if the file matches a glob.

2 Answers
const documentFilter: vscode.DocumentFilter = {
    pattern: '**/*.md',
};
const matches = vscode.languages.match(documentFilter, document) !== 0;

Glob | vscode.d.ts

Simple usage:

import * as vscode from 'vscode';

documentMatchGlob(doc: vscode.TextDocument, glob: string): boolean {
    return vscode.languages.match({ pattern: glob }, document) !== 0;
}
Related