-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add debug logs and dependabot
- Loading branch information
Showing
6 changed files
with
112 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { LogOutputChannel } from "vscode"; | ||
import { | ||
GoogleJavaFormatReleaseResponse, | ||
parseGoogleJavaFormatReleaseResponse, | ||
} from "./GoogleJavaFormatRelease"; | ||
import { logAsyncFunction } from "./logFunction"; | ||
|
||
export const getLatestReleaseOfGoogleJavaFormat = async () => { | ||
const response = await fetch( | ||
"https://api.github.com/repos/google/google-java-format/releases/latest", | ||
); | ||
if (!response.ok) { | ||
throw new Error("Failed to get latest release of Google Java Format."); | ||
} | ||
export const getLatestReleaseOfGoogleJavaFormat = logAsyncFunction( | ||
async function getLatestReleaseOfGoogleJavaFormat(log: LogOutputChannel) { | ||
const url = | ||
"https://api.github.com/repos/google/google-java-format/releases/latest"; | ||
log.debug("Fetching:", url); | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error( | ||
"Failed to get latest release of Google Java Format.", | ||
); | ||
} | ||
|
||
return parseGoogleJavaFormatReleaseResponse( | ||
(await response.json()) as GoogleJavaFormatReleaseResponse, | ||
); | ||
}; | ||
return parseGoogleJavaFormatReleaseResponse( | ||
(await response.json()) as GoogleJavaFormatReleaseResponse, | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import { LogOutputChannel } from "vscode"; | ||
import { GoogleJavaFormatVersion } from "./ExtensionConfiguration"; | ||
import { | ||
GoogleJavaFormatReleaseResponse, | ||
parseGoogleJavaFormatReleaseResponse, | ||
} from "./GoogleJavaFormatRelease"; | ||
import { logAsyncFunction } from "./logFunction"; | ||
|
||
export const getReleaseOfGoogleJavaFormatByVersion = async ( | ||
version: Exclude<GoogleJavaFormatVersion, "latest">, | ||
) => { | ||
const response = await fetch( | ||
`https://api.github.com/repos/google/google-java-format/releases/tags/v${version}`, | ||
); | ||
if (!response.ok) { | ||
throw new Error(`Failed to get v${version} of Google Java Format.`); | ||
} | ||
export const getReleaseOfGoogleJavaFormatByVersion = logAsyncFunction( | ||
async function getReleaseOfGoogleJavaFormatByVersion( | ||
log: LogOutputChannel, | ||
version: Exclude<GoogleJavaFormatVersion, "latest">, | ||
) { | ||
const url = `https://api.github.com/repos/google/google-java-format/releases/tags/v${version}`; | ||
log.debug("Fetching:", url); | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`Failed to get v${version} of Google Java Format.`); | ||
} | ||
|
||
return parseGoogleJavaFormatReleaseResponse( | ||
(await response.json()) as GoogleJavaFormatReleaseResponse, | ||
); | ||
}; | ||
return parseGoogleJavaFormatReleaseResponse( | ||
(await response.json()) as GoogleJavaFormatReleaseResponse, | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import { Uri } from "vscode"; | ||
import { LogOutputChannel, Uri } from "vscode"; | ||
import { logFunction } from "./logFunction"; | ||
|
||
export function getUriFromString(value: string) { | ||
try { | ||
return Uri.parse(value, true); | ||
} catch (e) { | ||
return Uri.file(value); | ||
} | ||
function isRemote(value: string | null) { | ||
return ( | ||
value !== null && | ||
(value.startsWith("http:/") || | ||
value.startsWith("https:/") || | ||
value.startsWith("file:/")) | ||
); | ||
} | ||
|
||
export const getUriFromString = logFunction(function getUriFromString( | ||
log: LogOutputChannel, | ||
value: string, | ||
) { | ||
return isRemote(value) ? Uri.parse(value, true) : Uri.file(value); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { LogOutputChannel } from "vscode"; | ||
|
||
export function logFunction<Args extends unknown[], R>( | ||
fn: (log: LogOutputChannel, ...args: Args) => R, | ||
) { | ||
return function (log: LogOutputChannel, ...args: Args) { | ||
log.debug( | ||
`Calling ${`"${fn.name}"` || "anonymous function"} with arguments:`, | ||
args, | ||
); | ||
try { | ||
const result = fn(log, ...args); | ||
log.debug( | ||
`${`"${fn.name}"` || "anonymous function"} returned:`, | ||
result, | ||
); | ||
return result; | ||
} catch (error) { | ||
log.error( | ||
`Error in ${`"${fn.name}"` || "anonymous function"}:`, | ||
error, | ||
); | ||
throw error; | ||
} | ||
}; | ||
} | ||
|
||
export function logAsyncFunction<Args extends unknown[], R>( | ||
fn: (log: LogOutputChannel, ...args: Args) => Promise<R>, | ||
) { | ||
return async function (log: LogOutputChannel, ...args: Args) { | ||
log.debug( | ||
`Calling ${`"${fn.name}"` || "anonymous function"} with arguments:`, | ||
args, | ||
); | ||
try { | ||
const result = await fn(log, ...args); | ||
log.debug( | ||
`${`"${fn.name}"` || "anonymous function"} returned:`, | ||
result, | ||
); | ||
return result; | ||
} catch (error) { | ||
log.error( | ||
`Error in ${`"${fn.name}"` || "anonymous function"}:`, | ||
error, | ||
); | ||
throw error; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters