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
70accc23
Commit
70accc23
authored
4 years ago
by
s1995588
Browse files
Options
Downloads
Patches
Plain Diff
Added a tool dropdown which is initialized by initializeTools.
Added a getParameters function to get parameters from LanguageServer.
parent
e98bf5d0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
media/main.js
+26
-10
26 additions, 10 deletions
media/main.js
media/vscode.css
+1
-1
1 addition, 1 deletion
media/vscode.css
src/commands.ts
+3
-1
3 additions, 1 deletion
src/commands.ts
src/extension.ts
+45
-5
45 additions, 5 deletions
src/extension.ts
with
75 additions
and
17 deletions
media/main.js
+
26
−
10
View file @
70accc23
//@ts-check
// This script will be run within the webview itself
// It cannot access the main VS Code APIs directly.
(
function
()
{
// @ts-ignore
const
vscode
=
acquireVsCodeApi
();
const
oldState
=
vscode
.
getState
()
||
{
definedConstants
:
[],
undefinedConstants
:
[],
options
:[]
};
const
oldState
=
vscode
.
getState
()
||
{
definedConstants
:
[],
undefinedConstants
:
[],
options
:
[]
};
let
undefinedConstants
=
oldState
.
undefinedConstants
;
let
definedConstants
=
oldState
.
definedConstants
;
let
options
=
oldState
.
options
;
console
.
log
(
"
Started
"
);
/**
* @type {HTMLSelectElement}
*/
const
toolDropDown
=
document
.
getElementById
(
"
tools
"
);
toolDropDown
.
addEventListener
(
'
change
'
,
event
=>
{
vscode
.
postMessage
({
type
:
"
toolSelected
"
,
toolName
:
toolDropDown
.
options
[
toolDropDown
.
selectedIndex
].
value
})
})
// Handle messages sent from the extension to the webview
window
.
addEventListener
(
'
message
'
,
event
=>
{
...
...
@@ -25,10 +28,25 @@
update
(
message
.
undefinedConstants
,
message
.
definedConstants
,
message
.
options
);
break
;
}
case
'
fillTools
'
:
{
fillTools
(
message
.
tools
);
break
;
}
}
});
function
fillTools
(
tools
)
{
const
select
=
document
.
querySelector
(
"
#tools
"
);
for
(
const
tool
of
tools
)
{
const
option
=
document
.
createElement
(
"
option
"
);
option
.
value
=
tool
;
option
.
text
=
tool
;
select
.
appendChild
(
option
);
}
}
/**
* @param {Array<{name: string, value: string}>} undefinedConstants
* @param {Array<{name: string, value: string}>} definedConstants
...
...
@@ -39,7 +57,7 @@
const
li
=
document
.
createElement
(
"
li
"
);
const
nameBox
=
document
.
createElement
(
"
input
"
);
nameBox
.
id
=
"
name-
"
+
name
;
nameBox
.
id
=
"
name-
"
+
name
;
nameBox
.
type
=
"
text
"
;
nameBox
.
value
=
name
;
nameBox
.
classList
.
add
(
"
name
"
);
...
...
@@ -47,7 +65,7 @@
li
.
appendChild
(
nameBox
);
const
valueBox
=
document
.
createElement
(
"
input
"
);
valueBox
.
id
=
"
value-
"
+
name
;
valueBox
.
id
=
"
value-
"
+
name
;
valueBox
.
type
=
"
text
"
;
valueBox
.
value
=
value
;
valueBox
.
classList
.
add
(
"
value
"
);
...
...
@@ -76,5 +94,3 @@
vscode
.
setState
({
definedConstants
:
definedConstants
,
undefinedConstants
:
undefinedConstants
,
options
:
options
});
}
}());
This diff is collapsed.
Click to expand it.
media/vscode.css
+
1
−
1
View file @
70accc23
...
...
@@ -74,7 +74,7 @@ button.secondary:hover {
}
input
:not
([
type
=
'checkbox'
]),
textarea
{
textarea
,
select
{
display
:
block
;
width
:
100%
;
border
:
none
;
...
...
This diff is collapsed.
Click to expand it.
src/commands.ts
+
3
−
1
View file @
70accc23
import
{
pathToFileURL
}
from
'
url
'
;
import
{
provider
,
modestExecutable
}
from
'
./extension
'
;
import
{
getParameters
,
client
,
provider
,
modestExecutable
}
from
'
./extension
'
;
import
*
as
vscode
from
'
vscode
'
;
import
*
as
path
from
"
path
"
;
import
{
LanguageClient
}
from
'
vscode-languageclient/node
'
;
export
namespace
ModestCommands
{
const
paramHistory
:
Map
<
string
,
string
>
=
new
Map
();
export
let
addParameters
=
vscode
.
commands
.
registerCommand
(
'
modest.add-parameters
'
,
async
()
=>
{
provider
.
sendMessage
({
type
:
"
update
"
,
...
...
This diff is collapsed.
Click to expand it.
src/extension.ts
+
45
−
5
View file @
70accc23
...
...
@@ -11,6 +11,7 @@ import {
LanguageClient
,
LanguageClientOptions
,
ServerOptions
,
TextDocumentIdentifier
,
TextEdit
,
Trace
,
TransportKind
...
...
@@ -19,9 +20,23 @@ import { ModestCommands } from "./commands";
import
*
as
path
from
"
path
"
;
import
{
fstat
,
existsSync
}
from
'
fs
'
;
let
client
:
LanguageClient
|
undefined
;
export
let
client
:
LanguageClient
|
undefined
;
export
let
provider
:
ModestSidebarProvider
;
interface
ModestTools
{
availableTools
:
Array
<
ModestTool
>
}
interface
ModestTool
{
name
:
string
,
parameters
:
Array
<
ModestParameter
>
}
interface
ModestParameter
{
usage
:
string
,
description
:
string
}
export
function
modestExecutable
():
string
|
undefined
{
let
executable
:
string
|
undefined
=
vscode
.
workspace
.
getConfiguration
(
"
modest
"
).
get
(
"
executableLocation
"
);
...
...
@@ -39,7 +54,7 @@ export function modestExecutable(): string | undefined {
return
executable
;
}
function
createClient
():
LanguageClient
|
undefined
{
function
createClient
():
LanguageClient
|
undefined
{
// TODO: Check if path exists for a better user experience(so it doesn't spam the user with errors)
// The server is implemented in node
...
...
@@ -104,6 +119,9 @@ function createClient(): LanguageClient | undefined{
clientOptions
);
client
.
registerProposedFeatures
();
client
.
trace
=
Trace
.
Verbose
;
client
.
onReady
().
then
(()
=>
initializeTools
()
)
return
client
;
}
...
...
@@ -140,6 +158,26 @@ export function activate(context: ExtensionContext) {
vscode
.
window
.
registerWebviewViewProvider
(
ModestSidebarProvider
.
viewType
,
provider
));
}
export
function
initializeTools
()
{
client
?.
sendRequest
<
any
>
(
"
modest/getTools
"
).
then
(
data
=>
{
const
toolNames
:
Array
<
string
>
=
data
.
availableTools
;
provider
.
sendMessage
({
type
:
"
fillTools
"
,
tools
:
toolNames
})
})
}
export
function
getParameters
(
toolName
:
string
)
{
let
uri
=
vscode
.
window
.
activeTextEditor
?.
document
.
uri
;
if
(
uri
)
{
let
JSONObject
=
{
"
TextDocument
"
:
TextDocumentIdentifier
.
create
(
uri
.
toString
()),
"
ToolName
"
:
toolName
}
client
?.
sendRequest
<
any
>
(
"
modest/getParameters
"
,
JSONObject
).
then
(
data
=>
{
console
.
log
(
data
);
})
}
}
export
function
deactivate
():
Thenable
<
void
>
|
undefined
{
if
(
!
client
)
{
...
...
@@ -147,6 +185,7 @@ export function deactivate(): Thenable<void> | undefined {
}
return
client
.
stop
();
}
class
ModestSidebarProvider
implements
vscode
.
WebviewViewProvider
{
public
static
readonly
viewType
=
'
modest.modestSidebar
'
;
...
...
@@ -170,12 +209,12 @@ class ModestSidebarProvider implements vscode.WebviewViewProvider {
};
webviewView
.
webview
.
html
=
this
.
_getHtmlForWebview
(
webviewView
.
webview
);
webviewView
.
webview
.
onDidReceiveMessage
(
data
=>
{
console
.
log
(
data
)
switch
(
data
.
type
)
{
case
'
color
Selected
'
:
case
'
tool
Selected
'
:
{
vscode
.
window
.
activeTextEditor
?.
insertSnippet
(
new
vscode
.
SnippetString
(
`#
${
data
.
value
}
`
)
);
getParameters
(
data
.
toolName
);
break
;
}
}
...
...
@@ -220,6 +259,7 @@ class ModestSidebarProvider implements vscode.WebviewViewProvider {
<title>Modest run dialog</title>
</head>
<body>
<select class="tools-dropdown" id="tools"> </select>
<h3>Undefined constants</h3>
<ul class="option-list" id="undefined-constants"> </ul>
<h3>Defined constants</h3>
...
...
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