11import { TextEditor , window , TextEditorDecorationType } from "vscode" ;
22import { Dependency } from "../types" ;
3- import { findDependencies } from "../utils/parsing" ;
3+ import { findDependencies } from "../utils/parsing/toml " ;
44import { getInstalledVersions } from "./poetry" ;
55import { getInfo } from "./api" ;
66import { getDecoration } from "./decorations" ;
77import { dirname } from "path" ;
8+ import { findDependenciesFromRequirementsTxt } from "../utils/parsing/requirements-txt" ;
89
910let decorationType : TextEditorDecorationType | null = null ;
1011
@@ -16,21 +17,22 @@ const updateVersions = (
1617 deps . map ( async ( dep ) => {
1718 const info = await getInfo ( dep . name ) ;
1819
19- dep . version . installed = installedVersions [ dep . name ] ;
20+ // dep.version.installed = installedVersions[dep.name];
2021 dep . version . latest = info . version ;
2122 dep . summary = info . summary ;
2223 } ) ,
2324 ) ;
2425} ;
2526
26- const doThings = async ( deps : Dependency [ ] , editor : TextEditor ) => {
27+ const decorateEditor = async ( deps : Dependency [ ] , editor : TextEditor ) => {
2728 if ( decorationType ) {
2829 decorationType . dispose ( ) ;
2930 }
3031
31- const installedVersions = await getInstalledVersions (
32- dirname ( editor . document . fileName ) ,
33- ) ;
32+ const installedVersions = { }
33+ // await getInstalledVersions(
34+ // dirname(editor.document.fileName),
35+ // );
3436
3537 await updateVersions ( deps , installedVersions ) ;
3638
@@ -43,24 +45,40 @@ const doThings = async (deps: Dependency[], editor: TextEditor) => {
4345 editor . setDecorations ( decorationType ! , decorations ) ;
4446} ;
4547
46- function parseAndDecorate ( editor : TextEditor ) {
48+ function parseAndDecorateToml ( editor : TextEditor ) {
4749 const text = editor . document . getText ( ) ;
48- // const config = workspace.getConfiguration("", editor.document.uri);
4950
5051 const deps = findDependencies ( text ) ;
5152
52- console . log ( "parsing and decorating" ) ;
53+ decorateEditor ( deps , editor ) ;
54+ }
55+
56+ function parseAndDecorateRequirementsTxt ( editor : TextEditor ) {
57+ const text = editor . document . getText ( ) ;
58+
59+ const deps = findDependenciesFromRequirementsTxt ( text ) ;
5360
54- doThings ( deps , editor ) ;
61+ decorateEditor ( deps , editor ) ;
5562}
5663
5764export const pyProjectListener = ( editor : TextEditor | undefined ) => {
5865 if ( editor ) {
5966 const { fileName } = editor . document ;
6067 if ( fileName . toLocaleLowerCase ( ) . endsWith ( "pyproject.toml" ) ) {
61- parseAndDecorate ( editor ) ;
68+ parseAndDecorateToml ( editor ) ;
69+ }
70+ }
71+ } ;
72+
73+ export const requirementsTxtListener = ( editor : TextEditor | undefined ) => {
74+ if ( editor ) {
75+ const fileName = editor . document . fileName . toLocaleLowerCase ( ) ;
76+
77+ if (
78+ fileName . endsWith ( "requirements.txt" ) ||
79+ fileName . endsWith ( "requirements.in" )
80+ ) {
81+ parseAndDecorateRequirementsTxt ( editor ) ;
6282 }
63- } else {
64- console . log ( "No active editor found." ) ;
6583 }
6684} ;
0 commit comments