vscode#DocumentFilter TypeScript Examples
The following examples show how to use
vscode#DocumentFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: extension.ts From typescript-explicit-types with GNU General Public License v3.0 | 6 votes |
export function activate(context: ExtensionContext) {
const selector: DocumentFilter[] = [];
for (const language of ['typescript', 'typescriptreact']) {
selector.push({ language, scheme: 'file' });
selector.push({ language, scheme: 'untitled' });
}
const command = commands.registerCommand(commandId, commandHandler);
const codeActionProvider = languages.registerCodeActionsProvider(selector, new GenereateTypeProvider(), GenereateTypeProvider.metadata);
context.subscriptions.push(command);
context.subscriptions.push(codeActionProvider);
}
Example #2
Source File: spConstants.ts From sourcepawn-vscode with MIT License | 5 votes |
SP_MODE: DocumentFilter = {
language: "sourcepawn",
scheme: "file",
}
Example #3
Source File: workspace.ts From vscode-code-review with MIT License | 4 votes |
registerCommands() {
this.openSelectionRegistration = commands.registerCommand(
'codeReview.openSelection',
(fileSection: ReviewFileExportSection, csvRef?: CsvEntry) => {
if (!this.generator.check()) {
return;
}
const filePath = path.join(this.workspaceRoot, fileSection.group);
workspace.openTextDocument(filePath).then(
(doc) => {
window.showTextDocument(doc, ViewColumn.One).then((textEditor) => {
if (csvRef) {
const ranges: Range[] = rangesFromStringDefinition(csvRef.lines);
textEditor.revealRange(ranges[0]);
this.webview.editComment(this.commentService, ranges, csvRef);
}
});
},
(err) => {
const msg = `Cannot not open file: '${filePath}': File does not exist.`;
window.showErrorMessage(msg);
},
);
},
);
/**
* register comment panel web view
*/
this.addNoteRegistration = commands.registerCommand('codeReview.addNote', () => {
if (!window.activeTextEditor?.selection) {
window.showErrorMessage(
`No selection made. Please select something you want to add a comment to and try again.`,
);
return;
}
// Execute every time a comment will be added to check file format
if (!this.generator.create()) {
return;
}
this.webview.addComment(this.commentService);
this.commentsProvider.refresh();
this.updateDecorations();
});
this.filterByCommitEnableRegistration = commands.registerCommand('codeReview.filterByCommitEnable', () => {
this.setFilterByCommit(true);
});
this.filterByCommitDisableRegistration = commands.registerCommand('codeReview.filterByCommitDisable', () => {
this.setFilterByCommit(false);
});
this.filterByFilenameEnableRegistration = commands.registerCommand('codeReview.filterByFilenameEnable', () => {
this.setFilterByFilename(true);
});
this.filterByFilenameDisableRegistration = commands.registerCommand('codeReview.filterByFilenameDisable', () => {
this.setFilterByFilename(false);
});
this.setReviewFileSelectedCsvRegistration = commands.registerCommand('codeReview.setReviewFileSelectedCsv', () => {
if (!window.activeTextEditor) {
window.showErrorMessage(`No CSV selected. Open a code-review CSV and re-run the command.`);
return;
}
const file = window.activeTextEditor.document.uri;
workspace.getConfiguration().update('code-review.filename', file.fsPath, null, undefined);
window.showInformationMessage(`Set code-review file to: ${file.fsPath}`);
});
/**
* delete an existing comment
*/
this.deleteNoteRegistration = commands.registerCommand('codeReview.deleteNote', (entry: CommentListEntry) => {
if (!this.generator.check()) {
return;
}
this.webview.deleteComment(this.commentService, entry);
this.commentsProvider.refresh();
this.updateDecorations();
});
/**
* allow users to export the report as HTML using the default output
*/
this.exportAsHtmlWithDefaultTemplateRegistration = commands.registerCommand(
'codeReview.exportAsHtmlWithDefaultTemplate',
() => {
this.exportFactory.exportForFormat('html', this.getDefaultTemplate());
},
);
/**
* allow users to export the report as HTML using a specific handlebars template
*/
this.exportAsHtmlWithHandlebarsTemplateRegistration = commands.registerCommand(
'codeReview.exportAsHtmlWithHandlebarsTemplate',
() => {
window
.showOpenDialog({
canSelectFolders: false,
canSelectFiles: true,
canSelectMany: false,
openLabel: 'Use template',
filters: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Template: ['hbs', 'html', 'htm', 'handlebars'],
},
})
.then((files) => {
const template = files?.length ? files[0] : undefined;
this.exportFactory.exportForFormat('html', template ?? this.getDefaultTemplate());
});
},
);
/**
* allow users to export the report as Markdown using the default output
*/
this.exportAsMarkdownWithDefaultTemplateRegistration = commands.registerCommand(
'codeReview.exportAsMarkdownWithDefaultTemplate',
() => {
this.exportFactory.exportForFormat('markdown', this.getDefaultMarkdownTemplate());
},
);
/**
* allow users to export the report as HTML using a specific handlebars template
*/
this.exportAsMarkdownWithHandlebarsTemplateRegistration = commands.registerCommand(
'codeReview.exportAsMarkdownWithHandlebarsTemplate',
() => {
window
.showOpenDialog({
canSelectFolders: false,
canSelectFiles: true,
canSelectMany: false,
openLabel: 'Use template',
filters: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Template: ['hbs', 'md', 'markdown', 'mdx', 'handlebars'],
},
})
.then((files) => {
const template = files?.length ? files[0] : undefined;
this.exportFactory.exportForFormat('markdown', template ?? this.defaultTemplate);
});
},
);
/**
* allow users to export the report as GitLab importable CSV file
*/
this.exportAsGitLabImportableCsvRegistration = commands.registerCommand(
'codeReview.exportAsGitLabImportableCsv',
() => {
this.exportFactory.exportForFormat('gitlab');
},
);
/**
* allow users to export the report as GitHub importable CSV file
* @see https://github.com/gavinr/github-csv-tools
*/
this.exportAsGitHubImportableCsvRegistration = commands.registerCommand(
'codeReview.exportAsGitHubImportableCsv',
() => {
this.exportFactory.exportForFormat('github');
},
);
/**
* allow users to export the report as JIRA importable CSV file
*/
this.exportAsJiraImportableCsvRegistration = commands.registerCommand(
'codeReview.exportAsJiraImportableCsv',
() => {
this.exportFactory.exportForFormat('jira');
},
);
/**
* allow users to export the report as JSON file
*/
this.exportAsJsonRegistration = commands.registerCommand('codeReview.exportAsJson', () => {
this.exportFactory.exportForFormat('json');
});
/**
* allow users to import comments from a JSON file
*/
this.importFromJsonRegistration = commands.registerCommand('codeReview.importFromJson', () => {
// File selection
window
.showOpenDialog({
canSelectFolders: false,
canSelectFiles: true,
canSelectMany: false,
openLabel: 'Select comments file to import',
filters: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Template: ['json'],
},
})
.then((files) => {
const filename = files?.length ? files[0] : undefined;
if (filename) {
const mode = workspace.getConfiguration().get('code-review.importConflictMode') as string;
if (mode !== '') {
this.importFactory.importCommentsFromFile(filename!.fsPath, mode as ConflictMode).then((result) => {
if (result) {
this.commentsProvider.refresh();
}
});
} else {
// Select the import conflict mode
class PickItem implements QuickPickItem {
constructor(
public mode: ConflictMode,
public label: string,
public description?: string | undefined,
public detail?: string | undefined,
public picked?: boolean | undefined,
public alwaysShow?: boolean | undefined,
) {}
}
window
.showQuickPick<PickItem>(
[
{
label: 'Skip',
description:
'In case of conflict, the existing comment will be kept and the imported one will be ignored.',
alwaysShow: true,
mode: ConflictMode.skipImported,
} as PickItem,
{
label: 'Overwrite',
description: 'In case of conflict, the existing comment will be replaced with the imported one.',
alwaysShow: true,
mode: ConflictMode.replaceWithImported,
} as PickItem,
{
label: 'Clone',
description: 'In case of conflict, both the existing and the imported comments will be kept.',
alwaysShow: true,
mode: ConflictMode.importCopy,
} as PickItem,
],
{
canPickMany: false,
placeHolder: 'Select the import conflict mode',
},
)
.then((item) => {
if (item) {
this.importFactory.importCommentsFromFile(filename!.fsPath, item.mode).then((result) => {
if (result) {
this.commentsProvider.refresh();
}
});
}
});
}
}
});
});
/**
* support code lens for comment annotations in files
*/
const ALL_FILES: DocumentFilter = { language: '*', scheme: 'file' };
this.commentCodeLensProviderregistration = languages.registerCodeLensProvider(
ALL_FILES,
new CommentLensProvider(this.exportFactory),
);
this.updateSubscriptions();
}