11// max-file-lines: legitimate parser — VSCode-decoration manager for per-document PURL hover/decoration rendering; the per-eco classification, per-PURL alert grouping, and per-editor decoration pipeline are tightly coupled and split poorly.
22import * as vscode from 'vscode'
3- import { SimPURL , parseExternals } from './externals/parse-externals'
3+ import { parseExternals } from './externals/parse-externals'
4+ import type { SimPURL } from './externals/parse-externals'
45import { PURLDataCache } from './purl-alerts-and-scores/manager'
5- import { PackageScoreAndAlerts } from './purl-alerts-and-scores/manager'
6+ import type { PackageScoreAndAlerts } from './purl-alerts-and-scores/manager'
67import { isGoBuiltin } from '../data/go/builtins'
78import { logger } from '../infra/log'
89import { PURLPackageData } from './purl-alerts-and-scores/manager'
910import { SUPPORTED_LSP_LANGUAGE_IDS_TO_PARSER } from './languages'
1011import { isPythonBuiltin } from '../data/python/interpreter'
1112import * as Module from 'node:module'
1213import { getGlobPatterns } from '../data/glob-patterns'
13- import { getDefaultLogger } from '@socketsecurity/lib/logger'
1414
1515export async function activate ( context : vscode . ExtensionContext ) {
1616 const decoManager = new DecorationManager ( context )
1717 const langs = Object . keys ( SUPPORTED_LSP_LANGUAGE_IDS_TO_PARSER )
1818 for ( let i = 0 , { length } = langs ; i < length ; i += 1 ) {
19- const lang = langs [ i ]
19+ const lang = langs [ i ] !
2020 vscode . languages . registerHoverProvider (
2121 {
2222 language : lang ,
@@ -33,14 +33,14 @@ export async function activate(context: vscode.ExtensionContext) {
3333 const patterns = await getGlobPatterns ( )
3434 const groupEntries = Object . entries ( patterns )
3535 for ( let i = 0 , { length } = groupEntries ; i < length ; i += 1 ) {
36- const patternsForGroup = groupEntries [ i ] [ 1 ]
36+ const patternsForGroup = groupEntries [ i ] ! [ 1 ]
3737 const groupEntryRows = Object . entries ( patternsForGroup )
3838 for (
3939 let j = 0 , { length : rowLength } = groupEntryRows ;
4040 j < rowLength ;
4141 j += 1
4242 ) {
43- const { pattern } = groupEntryRows [ j ] [ 1 ]
43+ const { pattern } = groupEntryRows [ j ] ! [ 1 ]
4444 vscode . languages . registerHoverProvider (
4545 {
4646 // language: 'json',
@@ -127,7 +127,7 @@ class DecorationManager {
127127 }
128128 const visibleEditors = vscode . window . visibleTextEditors
129129 for ( let i = 0 , { length } = visibleEditors ; i < length ; i += 1 ) {
130- const editor = visibleEditors [ i ]
130+ const editor = visibleEditors [ i ] !
131131 const docURI = editor . document . uri . toString ( ) as TextDocumentURIString
132132 const manager = managerForDoc ( docURI )
133133 manager . update ( editor . document )
@@ -137,7 +137,7 @@ class DecorationManager {
137137 if ( ! hasMeaningfulChange ) {
138138 const { contentChanges } = doc
139139 for ( let i = 0 , { length } = contentChanges ; i < length ; i += 1 ) {
140- const docChange = contentChanges [ i ]
140+ const docChange = contentChanges [ i ] !
141141 if ( docChange . rangeLength !== 0 ) {
142142 hasMeaningfulChange = true
143143 break
@@ -164,7 +164,7 @@ class DecorationManager {
164164 this . editorChangeWatchers = vscode . window . onDidChangeVisibleTextEditors (
165165 editors => {
166166 for ( let i = 0 , { length } = editors ; i < length ; i += 1 ) {
167- const editor = editors [ i ]
167+ const editor = editors [ i ] !
168168 const docURI = editor . document . uri . toString ( ) as TextDocumentURIString
169169 const manager = managerForDoc ( docURI )
170170 manager . decorateEditor ( editor )
@@ -222,10 +222,12 @@ export function isLocalPackage(name: string, eco: string): boolean {
222222 if ( eco === 'pypi' ) return name . startsWith ( '.' )
223223 if ( eco === 'go' ) {
224224 const parts = name . split ( '/' )
225+ const first = parts [ 0 ]
226+ if ( ! first ) return false
225227 return (
226228 parts . some ( p => p . startsWith ( '.' ) ) ||
227- ! parts [ 0 ] . includes ( '.' ) ||
228- ! / [ a - z 0 - 9 ] [ a - z 0 - 9 . - ] * / . test ( parts [ 0 ] )
229+ ! first . includes ( '.' ) ||
230+ ! / [ a - z 0 - 9 ] [ a - z 0 - 9 . - ] * / . test ( first )
229231 )
230232 }
231233 return false
@@ -325,7 +327,7 @@ class DecorationManagerForPURL {
325327 const {
326328 score : { overall : depscore } ,
327329 } = pkgData
328- const { eco, name } = getPURLParts ( this . purl ) !
330+ const { eco } = getPURLParts ( this . purl ) !
329331 const depscoreStr = ( depscore * 100 ) . toFixed ( 0 )
330332 const groupedAlerts = Object . groupBy ( pkgData . alerts , alert => alert . action )
331333
@@ -341,7 +343,7 @@ class DecorationManagerForPURL {
341343 // grouping is intentionally lossy — fewer dedup buckets keeps the hover readable when many alerts share a type.
342344 const typesListed = new Set < string > ( )
343345 for ( let i = 0 , { length } = actionGroupedAlertSet ; i < length ; i += 1 ) {
344- const alert = actionGroupedAlertSet [ i ]
346+ const alert = actionGroupedAlertSet [ i ] !
345347 // vscode markdown wants some kind of text for the table layout
346348 const extra = [ ]
347349 const alternatePackage = alert . props ?. alternatePackage
@@ -433,7 +435,7 @@ ${(['error', 'warn', 'monitor', 'ignore'] as const)
433435 const { alerts } = pkgData
434436 this . decorationType = decorationTypes . informativeDecoration
435437 for ( let i = 0 , { length } = alerts ; i < length ; i += 1 ) {
436- const { action } = alerts [ i ]
438+ const { action } = alerts [ i ] !
437439 if ( action === 'error' ) {
438440 this . decorationType = decorationTypes . errorDecoration
439441 break
@@ -453,13 +455,13 @@ class DecorationManagerForDocument {
453455 // parameterized, shared across all instances
454456 purlManagers : DecorationManagerForPURLCache
455457 async provideHover (
456- document : vscode . TextDocument ,
458+ _document : vscode . TextDocument ,
457459 position : vscode . Position ,
458460 ) : Promise < vscode . Hover | undefined > {
459461 // oxlint-disable-next-line socket/prefer-cached-for-loop -- iterating a Map.
460462 for ( const [ purl , { ranges } ] of this . externalRefs ) {
461463 for ( let i = 0 , { length } = ranges ; i < length ; i += 1 ) {
462- const range = ranges [ i ]
464+ const range = ranges [ i ] !
463465 const intersects = range . contains ( position )
464466 // logger.warn(document.getText(range), 'hovering over range', range, 'for purl', purl, 'intersects:', intersects, 'at position', position);
465467 if ( intersects ) {
@@ -528,7 +530,7 @@ class DecorationManagerForDocument {
528530 break
529531 }
530532 for ( let i = 0 , { length } = existing . ranges ; i < length ; i += 1 ) {
531- if ( ! ranges [ i ] . isEqual ( existing . ranges [ i ] ) ) {
533+ if ( ! ranges [ i ] ! . isEqual ( existing . ranges [ i ] ! ) ) {
532534 isDirty = true
533535 break check_each_purl_is_same_ranges
534536 }
@@ -592,7 +594,7 @@ class DecorationManagerForDocument {
592594 )
593595 const visibleEditors = vscode . window . visibleTextEditors
594596 for ( let i = 0 , { length } = visibleEditors ; i < length ; i += 1 ) {
595- const editor = visibleEditors [ i ]
597+ const editor = visibleEditors [ i ] !
596598 const editorURI = editor . document . uri . toString ( ) as TextDocumentURIString
597599 if ( editorURI === this . docURI ) {
598600 logger . debug ( `Matching editor ${ editorURI } for decoration update` )
0 commit comments