forked from konveyor/editor-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Implement Flux-style message passing (konveyor#125)
Changes: 1. convert ServerState enum to union type - enums are not native JS constructs and are not correctly packaged in the current build 2. unify data flow from extension to the webview - the entire state object is sent to keep the state atomic 3. provide type safe action creators (Redux-style) 4. provide generic map-based message handler similar to Redux reducers Signed-off-by: Radoslaw Szwajkowski <[email protected]>
- Loading branch information
Showing
17 changed files
with
417 additions
and
410 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 |
---|---|---|
@@ -1 +1 @@ | ||
export * from "./types/"; | ||
export * from "./types/index"; |
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,25 @@ | ||
export const SET_STATE = "SET_STATE"; | ||
export const START_ANALYSIS = "START_ANALYSIS"; | ||
export const START_SERVER = "START_SERVER"; | ||
export const CANCEL_SOLUTION = "CANCEL_SOLUTION"; | ||
export const GET_SOLUTION = "GET_SOLUTION"; | ||
export const OPEN_FILE = "OPEN_FILE"; | ||
export const VIEW_FIX = "VIEW_FIX"; | ||
export const APPLY_FILE = "APPLY_FILE"; | ||
export const DISCARD_FILE = "DISCARD_FILE"; | ||
|
||
export type WebviewActionType = | ||
| typeof SET_STATE | ||
| typeof START_ANALYSIS | ||
| typeof START_SERVER | ||
| typeof CANCEL_SOLUTION | ||
| typeof GET_SOLUTION | ||
| typeof OPEN_FILE | ||
| typeof VIEW_FIX | ||
| typeof APPLY_FILE | ||
| typeof DISCARD_FILE; | ||
|
||
export interface WebviewAction<S, T> { | ||
type: S; | ||
payload: T; | ||
} |
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,115 +1,2 @@ | ||
import { Uri } from "vscode"; | ||
|
||
export interface Incident { | ||
uri: string; | ||
lineNumber: number; | ||
severity: "High" | "Medium" | "Low"; | ||
message: string; | ||
codeSnip: string; | ||
} | ||
|
||
export interface Link { | ||
url: string; | ||
title?: string; | ||
} | ||
|
||
export enum Category { | ||
Potential = "potential", | ||
Optional = "optional", | ||
Mandatory = "mandatory", | ||
} | ||
|
||
export interface Violation { | ||
description: string; | ||
category?: Category; | ||
labels?: string[]; | ||
incidents: Incident[]; | ||
links?: Link[]; | ||
extras?: unknown; | ||
effort?: number; | ||
} | ||
|
||
export interface RuleSet { | ||
name?: string; | ||
description?: string; | ||
tags?: string[]; | ||
violations?: { [key: string]: Violation }; | ||
insights?: { [key: string]: Violation }; | ||
errors?: { [key: string]: string }; | ||
unmatched?: string[]; | ||
skipped?: string[]; | ||
} | ||
|
||
// KaiConfigModels type definition | ||
export interface KaiConfigModels { | ||
provider: string; | ||
args: Record<string, any>; | ||
template?: string; | ||
llamaHeader?: boolean; | ||
llmRetries: number; | ||
llmRetryDelay: number; | ||
} | ||
|
||
// KaiRpcApplicationConfig type definition | ||
export interface KaiInitializeParams { | ||
rootPath: string; | ||
modelProvider: KaiConfigModels; | ||
kaiBackendUrl: string; | ||
|
||
logLevel: string; | ||
stderrLogLevel: string; | ||
fileLogLevel?: string; | ||
logDirPath?: string; | ||
|
||
analyzerLspLspPath: string; | ||
analyzerLspRpcPath: string; | ||
analyzerLspRulesPath: string; | ||
analyzerLspJavaBundlePath: string; | ||
} | ||
|
||
export interface GetSolutionParams { | ||
file_path: string; | ||
incidents: Incident[]; | ||
} | ||
export interface Change { | ||
// relative file path before the change, may be empty if file was created in this change | ||
original: string; | ||
// relative file path after the change, may be empty if file was deleted in this change | ||
modified: string; | ||
// diff in unified format - tested with git diffs | ||
diff: string; | ||
} | ||
|
||
export interface GetSolutionResult { | ||
encountered_errors: string[]; | ||
changes: Change[]; | ||
scope: Scope; | ||
} | ||
|
||
export interface LocalChange { | ||
modifiedUri: Uri; | ||
originalUri: Uri; | ||
diff: string; | ||
state: "pending" | "applied" | "discarded"; | ||
} | ||
|
||
export interface ResolutionMessage { | ||
type: string; | ||
solution: Solution; | ||
violation: Violation; | ||
incident: Incident; | ||
isRelevantSolution: boolean; | ||
} | ||
|
||
export interface SolutionResponse { | ||
diff: string; | ||
encountered_errors: string[]; | ||
modified_files: string[]; | ||
} | ||
|
||
export interface Scope { | ||
incident: Incident; | ||
violation?: Violation; | ||
} | ||
|
||
export type Solution = GetSolutionResult | SolutionResponse; | ||
export * from "./actions"; | ||
export * from "./types"; |
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,135 @@ | ||
import { Uri } from "vscode"; | ||
|
||
export interface Incident { | ||
uri: string; | ||
lineNumber: number; | ||
severity: "High" | "Medium" | "Low"; | ||
message: string; | ||
codeSnip: string; | ||
} | ||
|
||
export interface Link { | ||
url: string; | ||
title?: string; | ||
} | ||
|
||
export enum Category { | ||
Potential = "potential", | ||
Optional = "optional", | ||
Mandatory = "mandatory", | ||
} | ||
|
||
export interface Violation { | ||
description: string; | ||
category?: Category; | ||
labels?: string[]; | ||
incidents: Incident[]; | ||
links?: Link[]; | ||
extras?: unknown; | ||
effort?: number; | ||
} | ||
|
||
export interface RuleSet { | ||
name?: string; | ||
description?: string; | ||
tags?: string[]; | ||
violations?: { [key: string]: Violation }; | ||
insights?: { [key: string]: Violation }; | ||
errors?: { [key: string]: string }; | ||
unmatched?: string[]; | ||
skipped?: string[]; | ||
} | ||
|
||
// KaiConfigModels type definition | ||
export interface KaiConfigModels { | ||
provider: string; | ||
args: Record<string, any>; | ||
template?: string; | ||
llamaHeader?: boolean; | ||
llmRetries: number; | ||
llmRetryDelay: number; | ||
} | ||
|
||
// KaiRpcApplicationConfig type definition | ||
export interface KaiInitializeParams { | ||
rootPath: string; | ||
modelProvider: KaiConfigModels; | ||
kaiBackendUrl: string; | ||
|
||
logLevel: string; | ||
stderrLogLevel: string; | ||
fileLogLevel?: string; | ||
logDirPath?: string; | ||
|
||
analyzerLspLspPath: string; | ||
analyzerLspRpcPath: string; | ||
analyzerLspRulesPath: string; | ||
analyzerLspJavaBundlePath: string; | ||
} | ||
|
||
export interface GetSolutionParams { | ||
file_path: string; | ||
incidents: Incident[]; | ||
} | ||
export interface Change { | ||
// relative file path before the change, may be empty if file was created in this change | ||
original: string; | ||
// relative file path after the change, may be empty if file was deleted in this change | ||
modified: string; | ||
// diff in unified format - tested with git diffs | ||
diff: string; | ||
} | ||
|
||
export interface GetSolutionResult { | ||
encountered_errors: string[]; | ||
changes: Change[]; | ||
scope: Scope; | ||
} | ||
|
||
export interface LocalChange { | ||
modifiedUri: Uri; | ||
originalUri: Uri; | ||
diff: string; | ||
state: "pending" | "applied" | "discarded"; | ||
} | ||
|
||
export interface ResolutionMessage { | ||
type: string; | ||
solution: Solution; | ||
violation: Violation; | ||
incident: Incident; | ||
isRelevantSolution: boolean; | ||
} | ||
|
||
export interface SolutionResponse { | ||
diff: string; | ||
encountered_errors: string[]; | ||
modified_files: string[]; | ||
} | ||
|
||
export interface Scope { | ||
incident: Incident; | ||
violation?: Violation; | ||
} | ||
|
||
export type Solution = GetSolutionResult | SolutionResponse; | ||
|
||
export interface ExtensionData { | ||
localChanges: LocalChange[]; | ||
ruleSets: RuleSet[]; | ||
resolutionPanelData: any; | ||
isAnalyzing: boolean; | ||
isFetchingSolution: boolean; | ||
isStartingServer: boolean; | ||
serverState: ServerState; | ||
solutionData?: Solution; | ||
solutionScope?: Scope; | ||
} | ||
|
||
export type ServerState = | ||
| "initial" | ||
| "starting" | ||
| "startFailed" | ||
| "running" | ||
| "stopping" | ||
| "stopped"; |
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.