-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* spectral install and update, dsn validation
- Loading branch information
Showing
15 changed files
with
385 additions
and
331 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 |
---|---|---|
|
@@ -16,4 +16,5 @@ | |
# Checklist | ||
- [ ] Tests | ||
- [ ] Documentation | ||
- [ ] Linting | ||
- [ ] Linting | ||
- [ ] Change log |
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
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
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
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
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
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,31 @@ | ||
import * as vscode from 'vscode' | ||
|
||
export class PersistenceContext { | ||
private context?: vscode.ExtensionContext | ||
private static instance: PersistenceContext | ||
|
||
public static getInstance() { | ||
if (!this.instance) { | ||
this.instance = new PersistenceContext() | ||
} | ||
|
||
return this.instance | ||
} | ||
|
||
setContext(context: vscode.ExtensionContext): void { | ||
this.context = context | ||
} | ||
|
||
getGlobalStateValue<T>(key: string): T | undefined { | ||
return this.acquireContext().globalState.get(key) | ||
} | ||
|
||
updateGlobalStateValue(key: string, value: unknown): Thenable<void> { | ||
return this.acquireContext().globalState.update(key, value) | ||
} | ||
|
||
private acquireContext(): vscode.ExtensionContext { | ||
if (!this.context) throw new Error('VS Code extension context not set.') | ||
return this.context | ||
} | ||
} |
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,21 @@ | ||
import { Configuration } from './configuration' | ||
import { AGENT_LAST_UPDATE_DATE } from './constants' | ||
import { PersistenceContext } from './persistence-context' | ||
|
||
export const shouldUpdateSpectralAgent = (): boolean => { | ||
return ( | ||
isOverUpdateThreshold() && Configuration.getInstance().isAutoUpdateEnabled | ||
) | ||
} | ||
|
||
const isOverUpdateThreshold = (): boolean => { | ||
const lastUpdateDate = | ||
PersistenceContext.getInstance().getGlobalStateValue<number>( | ||
AGENT_LAST_UPDATE_DATE | ||
) | ||
if (!lastUpdateDate) { | ||
return true | ||
} | ||
const oneWeekInMs = 7 * 24 * 3600 * 1000 | ||
return Date.now() - lastUpdateDate > oneWeekInMs | ||
} |
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
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
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
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
Oops, something went wrong.