Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public onDefinition = async (line: string, uri: string): Promise => {
let matches = /(.*)(script\.([\S]*))([\s]*)*(.*)/.exec(line);
if (!matches || matches.length !== 6) {
return [];
}
let scripts = await this.haConfig.getScripts();
var scriptName = matches[3].replace(":", ""); // might be possible in regex!?
let ourScript = scripts[scriptName];
if (!ourScript) {
return [];
}
return [Location.create(ourScript.fileUri, {
start: { line: ourScript.start[0], character: ourScript.start[1] },
end: { line: ourScript.end[0], character: ourScript.end[1] }
})];
}
}
public async handleLocations(definition: Definition | LocationLink[], openCommand?: string | false): Promise {
if (!definition) return
let locations: Location[] = Array.isArray(definition) ? definition as Location[] : [definition]
let len = locations.length
if (len == 0) return
if (len == 1 && openCommand !== false) {
let location = definition[0] as Location
if (LocationLink.is(definition[0])) {
let link = definition[0] as LocationLink
location = Location.create(link.targetUri, link.targetRange)
}
let { uri, range } = location
await workspace.jumpTo(uri, range.start, openCommand)
} else {
await workspace.showLocations(definition as Location[])
}
}
public async handleLocations(definition: Definition | LocationLink[], openCommand?: string): Promise {
if (!definition) return
if (Array.isArray(definition)) {
let len = definition.length
if (len == 0) return
if (len == 1) {
let location = definition[0] as Location
if (LocationLink.is(definition[0])) {
let link = definition[0] as LocationLink
location = Location.create(link.targetUri, link.targetRange)
}
let { uri, range } = location
await workspace.jumpTo(uri, range.start, openCommand)
} else {
await workspace.showLocations(definition as Location[])
}
} else {
let { uri, range } = definition as Location
await workspace.jumpTo(uri, range.start, openCommand)
}
}
break
case 11:
msg = 'unexpected end of comment'
break
case 4:
msg = 'value expected'
break
default:
msg = 'Unknwn error'
break
}
let range: Range = {
start: document.positionAt(err.offset),
end: document.positionAt(err.offset + err.length),
}
let loc = Location.create(uri, range)
items.push({ location: loc, message: msg })
}
return items
}
async lineLocation(
uri: PathLike | URI,
lineNumber: number
): Promise {
uri = this.asUri(uri).with({ scheme: 'file' });
return Location.create(
uri.toString(),
await this.lineRange(uri, lineNumber)
);
}