Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IDE-Plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DP-Group 14
IDE-Plugin
Commits
3eb0cfd5
Commit
3eb0cfd5
authored
4 years ago
by
s1995588
Browse files
Options
Downloads
Patches
Plain Diff
Constants are now saved per document.
parent
45aa6d04
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
media/main.js
+65
-15
65 additions, 15 deletions
media/main.js
src/extension.ts
+27
-16
27 additions, 16 deletions
src/extension.ts
with
92 additions
and
31 deletions
media/main.js
+
65
−
15
View file @
3eb0cfd5
...
...
@@ -3,10 +3,6 @@
(
function
()
{
const
vscode
=
acquireVsCodeApi
();
const
oldState
=
vscode
.
getState
()
||
{
constants
:
[],
options
:
[]
};
let
constants
=
oldState
.
constants
;
let
options
=
oldState
.
options
;
console
.
log
(
"
Started
"
);
/**
...
...
@@ -24,7 +20,7 @@
switch
(
message
.
type
)
{
case
'
updateConstants
'
:
{
updateConstants
(
message
.
constants
);
updateConstants
(
message
.
constants
,
message
.
uri
);
break
;
}
case
'
updateOptions
'
:
...
...
@@ -43,15 +39,20 @@
function
fillTools
(
tools
)
{
const
select
=
document
.
querySelector
(
"
#tools
"
);
select
.
innerHTML
=
""
;
for
(
const
tool
of
tools
)
{
const
option
=
document
.
createElement
(
"
option
"
);
option
.
value
=
tool
;
option
.
text
=
tool
;
select
.
appendChild
(
option
);
}
const
oldState
=
vscode
.
getState
()
||
{
tools
:
[],
constants
:
[],
options
:
[]
};
vscode
.
setState
({
tools
:
tools
,
constants
:
oldState
.
constants
,
options
:
oldState
.
options
});
}
function
addConstantItem
(
ul
,
name
)
{
function
addConstantItem
(
ul
,
name
,
value
)
{
const
li
=
document
.
createElement
(
"
li
"
);
const
nameBox
=
document
.
createElement
(
"
label
"
);
...
...
@@ -64,7 +65,23 @@
const
valueBox
=
document
.
createElement
(
"
input
"
);
valueBox
.
id
=
"
value-
"
+
name
;
valueBox
.
type
=
"
text
"
;
valueBox
.
value
=
value
;
valueBox
.
classList
.
add
(
"
value
"
);
valueBox
.
addEventListener
(
"
input
"
,
event
=>
{
let
oldState
=
vscode
.
getState
();
for
(
const
file
of
oldState
.
constants
)
{
if
(
file
.
uri
===
oldState
.
currentUri
)
{
for
(
const
constant
of
file
.
constants
)
{
if
(
constant
.
name
===
name
)
{
constant
.
value
=
valueBox
.
value
;
break
;
}
}
break
;
}
}
vscode
.
setState
({
tools
:
oldState
.
tools
,
constants
:
oldState
.
constants
,
options
:
oldState
.
options
,
currentUri
:
oldState
.
currentUri
});
});
li
.
appendChild
(
valueBox
);
...
...
@@ -94,18 +111,37 @@
}
/**
* @param {Array<string>} constants
*
* @param {Array<{ uri: string, constants: Array<{ name: string, value: string }> }>} constants
* @param {string} uri
*/
function
updateConstants
(
constants
)
{
function
updateConstants
(
constants
,
uri
)
{
const
constantsUl
=
document
.
querySelector
(
"
#constants
"
);
const
oldState
=
vscode
.
getState
();
for
(
const
file
of
constants
)
{
for
(
const
constant
of
file
.
constants
)
{
const
index
=
oldState
.
constants
.
findIndex
(
x
=>
x
.
uri
===
file
.
uri
);
if
(
index
!==
-
1
)
{
const
oldConstantIndex
=
oldState
.
constants
[
index
].
constants
.
findIndex
(
x
=>
x
.
name
===
constant
.
name
);
if
(
oldConstantIndex
!==
-
1
)
{
constant
.
value
=
oldState
.
constants
[
index
].
constants
[
oldConstantIndex
].
value
;
}
}
}
}
constantsUl
.
innerHTML
=
""
;
for
(
const
constant
of
constants
)
{
addConstantItem
(
constantsUl
,
constant
);
for
(
const
file
of
constants
)
{
if
(
file
.
uri
===
uri
)
{
for
(
const
constant
of
file
.
constants
)
{
addConstantItem
(
constantsUl
,
constant
.
name
,
constant
.
value
);
}
break
;
}
}
vscode
.
setState
({
constants
:
constants
});
vscode
.
setState
({
tools
:
oldState
.
tools
,
constants
:
constants
,
options
:
oldState
.
options
,
currentUri
:
uri
});
}
/**
...
...
@@ -115,11 +151,25 @@
const
optionsUl
=
document
.
querySelector
(
"
#options
"
);
optionsUl
.
innerHTML
=
""
;
for
(
const
option
of
options
)
{
add
List
Item
(
optionsUl
,
option
.
name
,
option
.
value
);
add
Option
Item
(
optionsUl
,
option
.
name
,
option
.
value
);
}
vscode
.
setState
({
options
:
options
});
const
oldState
=
vscode
.
getState
();
vscode
.
setState
({
tools
:
oldState
.
tools
,
constants
:
oldState
.
constants
,
options
:
options
,
currentUri
:
oldState
.
currentUri
});
}
vscode
.
postMessage
({
type
:
"
init
"
});
const
oldState
=
vscode
.
getState
()
||
{
tools
:
[],
constants
:
[],
options
:
[],
currentUri
:
""
};
const
tools
=
oldState
.
tools
;
const
constants
=
oldState
.
constants
;
const
options
=
oldState
.
options
;
const
currentUri
=
oldState
.
currentUri
;
if
(
oldState
.
tools
.
length
===
0
)
{
vscode
.
postMessage
({
type
:
"
init
"
});
}
else
{
fillTools
(
tools
);
updateOptions
(
options
);
updateConstants
(
constants
,
currentUri
);
}
}());
This diff is collapsed.
Click to expand it.
src/extension.ts
+
27
−
16
View file @
3eb0cfd5
...
...
@@ -23,7 +23,7 @@ import { fstat, existsSync } from 'fs';
export
let
client
:
LanguageClient
|
undefined
;
export
let
provider
:
ModestSidebarProvider
;
let
toolNames
:
Array
<
string
>
|
undefined
;
let
constants
:
Array
<
string
>
|
undefined
;
let
constants
:
Array
<
{
uri
:
string
,
constants
:
Array
<
{
name
:
string
,
value
:
string
}
>
}
>
=
[]
;
interface
ModestTools
{
availableTools
:
Array
<
ModestTool
>
...
...
@@ -155,12 +155,14 @@ export function activate(context: ExtensionContext) {
});
vscode
.
window
.
onDidChangeActiveTextEditor
(
textEditor
=>
{
if
(
textEditor
)
getConstants
(
textEditor
.
document
);
})
if
(
textEditor
)
{
getConstants
(
textEditor
.
document
);
}
});
vscode
.
workspace
.
onDidSaveTextDocument
(
textEditor
=>
{
getConstants
(
textEditor
)
})
getConstants
(
textEditor
)
;
})
;
provider
=
new
ModestSidebarProvider
(
context
.
extensionUri
);
...
...
@@ -179,24 +181,33 @@ function initializeTools() {
}
function
getConstants
(
document
:
TextDocument
)
{
if
(
document
.
languageId
==
"
modest
"
)
{
let
uri
=
document
.
uri
;
if
(
uri
)
{
let
JSONObject
=
{
"
TextDocument
"
:
TextDocumentIdentifier
.
create
(
uri
.
toString
())
};
client
?.
sendRequest
<
any
>
(
"
modest/getConstants
"
,
JSONObject
).
then
(
data
=>
{
constants
=
data
if
(
document
.
languageId
===
"
modest
"
)
{
if
(
document
.
uri
)
{
let
uri
=
document
.
uri
.
toString
();
let
jsonObject
=
{
"
TextDocument
"
:
TextDocumentIdentifier
.
create
(
uri
)
};
client
?.
sendRequest
<
Array
<
string
>>
(
"
modest/getConstants
"
,
jsonObject
).
then
(
data
=>
{
const
index
=
constants
.
findIndex
(
x
=>
x
.
uri
===
uri
);
const
newConstants
=
data
.
map
(
constant
=>
{
return
{
name
:
constant
,
value
:
""
};
});
if
(
index
===
-
1
)
{
constants
.
push
({
"
uri
"
:
uri
,
constants
:
newConstants
});
}
else
{
constants
[
index
].
constants
=
newConstants
;
}
provider
.
sendMessage
({
type
:
"
updateConstants
"
,
constants
:
constants
})
constants
:
constants
,
"
uri
"
:
uri
});
});
}
}
}
function
getOptions
(
toolName
:
string
)
{
let
JSON
Object
=
{
"
ToolName
"
:
toolName
};
client
?.
sendRequest
<
any
>
(
"
modest/getOptions
"
,
JSON
Object
).
then
(
data
=>
{
let
json
Object
=
{
"
ToolName
"
:
toolName
};
client
?.
sendRequest
<
any
>
(
"
modest/getOptions
"
,
json
Object
).
then
(
data
=>
{
console
.
log
(
data
);
// provider.sendMessage({
// type: "updateOptions",
...
...
@@ -250,7 +261,7 @@ class ModestSidebarProvider implements vscode.WebviewViewProvider {
provider
.
sendMessage
({
type
:
"
updateConstants
"
,
constants
:
constants
})
})
;
}
break
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment