File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -295,4 +295,19 @@ describe('linter', () => {
295295 diagnostics : [ ] ,
296296 } )
297297 } )
298+
299+ it ( 'should handle non-file URI schemes gracefully' , async ( ) => {
300+ const shell = [ '#!/bin/bash' , 'echo "hello"' ] . join ( '\n' )
301+
302+ const nonFileUri = 'webdav://example.com/path/to/script.sh'
303+ const document = TextDocument . create ( nonFileUri , 'bash' , 0 , shell )
304+
305+ const [ result ] = await getLintingResult ( {
306+ document,
307+ sourcePaths : [ ] ,
308+ } )
309+
310+ expect ( result . diagnostics ) . toEqual ( [ ] )
311+ expect ( result . codeActions ) . toEqual ( { } )
312+ } )
298313} )
Original file line number Diff line number Diff line change 11import { dirname } from 'node:path'
2- import { fileURLToPath } from 'node:url'
2+ import { fileURLToPath , URL } from 'node:url'
33
44import { spawn } from 'child_process'
55import * as LSP from 'vscode-languageserver/node'
@@ -17,6 +17,19 @@ import {
1717} from './types'
1818
1919const DEBOUNCE_MS = 500
20+
21+ function safeFileURLToPath ( uri : string ) : string | null {
22+ try {
23+ const url = new URL ( uri )
24+ if ( url . protocol !== 'file:' ) {
25+ return null
26+ }
27+ return fileURLToPath ( uri )
28+ } catch {
29+ return null
30+ }
31+ }
32+
2033type LinterOptions = {
2134 executablePath : string
2235 cwd ?: string
@@ -91,10 +104,15 @@ export class Linter {
91104 return { diagnostics : [ ] , codeActions : { } }
92105 }
93106
107+ const documentPath = safeFileURLToPath ( document . uri )
108+ const effectiveSourcePaths = documentPath
109+ ? [ ...sourcePaths , dirname ( documentPath ) ]
110+ : sourcePaths
111+
94112 const result = await this . runShellCheck (
95113 documentText ,
96114 shellName ,
97- [ ... sourcePaths , dirname ( fileURLToPath ( document . uri ) ) ] ,
115+ effectiveSourcePaths ,
98116 additionalShellCheckArguments ,
99117 )
100118
You can’t perform that action at this time.
0 commit comments