FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
modelscript/extensions/vscode/src/scmTreeView.ts at main · modelscript/modelscript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
modelscript
/
modelscript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
3
Star
12
Code
Issues
1
Pull requests
5
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
modelscript
/
extensions
/
vscode
/
src
/
scmTreeView.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
137 lines (111 loc) · 4.62 KB
Breadcrumbs
modelscript
/
extensions
/
vscode
/
src
/
scmTreeView.ts
Copy path
File metadata and controls
137 lines (111 loc) · 4.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import
*
as
vscode
from
"vscode"
;
import
{
LanguageClient
}
from
"vscode-languageclient/browser"
;
import
{
FlatSemanticEdit
}
from
"./semanticDiffComments"
;
// actually, we should define it locally or import from where it is shared
// We'll define the interface locally to avoid circular dependencies if any
interface
SemanticEditNode
{
action
:
"insert"
|
"delete"
|
"update"
|
"none"
;
description
:
string
;
kind
?:
string
;
uri
:
vscode
.
Uri
;
}
class
SemanticDiffTreeItem
extends
vscode
.
TreeItem
{
constructor
(
public
readonly
edit
:
SemanticEditNode
)
{
super
(
edit
.
description
,
vscode
.
TreeItemCollapsibleState
.
None
)
;
this
.
tooltip
=
edit
.
description
;
// Set icon based on action
if
(
edit
.
action
===
"insert"
)
{
this
.
iconPath
=
new
vscode
.
ThemeIcon
(
"add"
,
new
vscode
.
ThemeColor
(
"gitDecoration.addedResourceForeground"
)
)
;
}
else
if
(
edit
.
action
===
"delete"
)
{
this
.
iconPath
=
new
vscode
.
ThemeIcon
(
"trash"
,
new
vscode
.
ThemeColor
(
"gitDecoration.deletedResourceForeground"
)
)
;
}
else
if
(
edit
.
action
===
"update"
)
{
this
.
iconPath
=
new
vscode
.
ThemeIcon
(
"edit"
,
new
vscode
.
ThemeColor
(
"gitDecoration.modifiedResourceForeground"
)
)
;
}
else
{
this
.
iconPath
=
new
vscode
.
ThemeIcon
(
"info"
)
;
}
// Add file context
const
filename
=
edit
.
uri
.
path
.
split
(
"/"
)
.
pop
(
)
;
this
.
description
=
filename
;
}
}
class
SemanticDiffTreeProvider
implements
vscode
.
TreeDataProvider
<
SemanticDiffTreeItem
>
{
private
_onDidChangeTreeData
:
vscode
.
EventEmitter
<
SemanticDiffTreeItem
|
undefined
>
=
new
vscode
.
EventEmitter
<
SemanticDiffTreeItem
|
undefined
>
(
)
;
readonly
onDidChangeTreeData
:
vscode
.
Event
<
SemanticDiffTreeItem
|
undefined
>
=
this
.
_onDidChangeTreeData
.
event
;
private
items
:
SemanticDiffTreeItem
[
]
=
[
]
;
constructor
(
private
client
:
LanguageClient
|
undefined
)
{
}
refresh
(
)
:
void
{
this
.
_onDidChangeTreeData
.
fire
(
undefined
)
;
}
getTreeItem
(
element
:
SemanticDiffTreeItem
)
:
vscode
.
TreeItem
{
return
element
;
}
async
getChildren
(
element
?:
SemanticDiffTreeItem
)
:
Promise
<
SemanticDiffTreeItem
[
]
>
{
if
(
element
)
{
return
[
]
;
// We're keeping it flat for now, grouping by file could be next
}
if
(
!
this
.
client
)
return
[
]
;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const
gitExtension
=
vscode
.
extensions
.
getExtension
<
any
>
(
"vscode.git"
)
?.
exports
;
if
(
!
gitExtension
)
return
[
]
;
const
git
=
gitExtension
.
getAPI
(
1
)
;
if
(
!
git
||
git
.
repositories
.
length
===
0
)
return
[
]
;
const
repository
=
git
.
repositories
[
0
]
;
const
changes
=
repository
.
state
.
indexChanges
;
if
(
!
changes
||
changes
.
length
===
0
)
return
[
]
;
const
resultItems
:
SemanticDiffTreeItem
[
]
=
[
]
;
for
(
const
change
of
changes
)
{
const
uri
=
change
.
uri
;
if
(
!
(
uri
.
fsPath
.
endsWith
(
".mo"
)
||
uri
.
fsPath
.
endsWith
(
".sysml"
)
)
)
{
continue
;
}
try
{
const
oldText
=
await
repository
.
show
(
"HEAD"
,
uri
.
fsPath
)
;
const
newTextBytes
=
await
vscode
.
workspace
.
fs
.
readFile
(
uri
)
;
const
newText
=
new
TextDecoder
(
)
.
decode
(
newTextBytes
)
;
if
(
!
oldText
||
!
newText
||
oldText
===
newText
)
continue
;
const
result
=
await
this
.
client
.
sendRequest
<
{
diffs
:
FlatSemanticEdit
[
]
}
>
(
"modelscript/getSemanticDiff"
,
{
uri
:
uri
.
toString
(
)
,
oldText
,
newText
,
}
)
;
if
(
result
&&
result
.
diffs
)
{
for
(
const
diff
of
result
.
diffs
)
{
if
(
diff
.
action
!==
"none"
&&
diff
.
description
)
{
resultItems
.
push
(
new
SemanticDiffTreeItem
(
{
action
:
diff
.
action
,
description
:
diff
.
description
,
kind
:
diff
.
kind
,
uri
:
uri
,
}
)
,
)
;
}
}
}
}
catch
(
e
)
{
console
.
error
(
"Failed to get semantic diff for"
,
uri
.
fsPath
,
e
)
;
}
}
this
.
items
=
resultItems
;
return
this
.
items
;
}
}
export
function
registerScmTreeView
(
context
:
vscode
.
ExtensionContext
,
client
:
LanguageClient
|
undefined
)
{
const
treeProvider
=
new
SemanticDiffTreeProvider
(
client
)
;
context
.
subscriptions
.
push
(
vscode
.
window
.
registerTreeDataProvider
(
"modelscript.scmTreeView"
,
treeProvider
)
)
;
// Refresh when git state changes
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const
gitExtension
=
vscode
.
extensions
.
getExtension
<
any
>
(
"vscode.git"
)
?.
exports
;
if
(
gitExtension
)
{
const
git
=
gitExtension
.
getAPI
(
1
)
;
if
(
git
&&
git
.
repositories
.
length
>
0
)
{
const
repo
=
git
.
repositories
[
0
]
;
context
.
subscriptions
.
push
(
repo
.
state
.
onDidChange
(
(
)
=>
{
treeProvider
.
refresh
(
)
;
}
)
,
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL