Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelizimm committed Sep 10, 2024
1 parent 825eeab commit f21b7b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions extensions/positron-python/src/client/positron/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ export async function activatePositron(

// set contexts
const fileOpenListener = vscode.workspace.onDidOpenTextDocument((document) => {
if (document.languageId == 'python') {
if (document.languageId === 'python') {
detectWebApp(document);
}
});
const activeEditorListener = vscode.window.onDidChangeActiveTextEditor((editor) => {
if (editor && editor.document.languageId == 'python') {
if (editor && editor.document.languageId === 'python') {
detectWebApp(editor.document);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const libraries: string[] = ['streamlit', 'shiny', 'gradio', 'flask', 'fastapi']

export function detectWebApp(document: vscode.TextDocument): void {
const text = document.getText();
const foundImports = importsInApp(text, libraries);
const foundImports = importsInApp(text);
vscode.commands.executeCommand('setContext', 'pythonFileContainsApp', foundImports);
console.log('set context pythonFileContainsApp', foundImports);
}

// find import statements for specified libraries via import XXXX or from XXX import
function importsInApp(text: string, libraries: string[]): boolean {
function importsInApp(text: string): boolean {
const importPattern = new RegExp(`import\\s+(${libraries.join('|')})`, 'g');
const fromImportPattern = new RegExp(`from\\s+(${libraries.join('|')})\\S*\\simport`, 'g');

Expand Down

0 comments on commit f21b7b0

Please sign in to comment.