FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/src/client/helpProvider.ts at debugUnit · dannyzed/pythonVSCode · GitHub
dannyzed
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
src
/
client
/
helpProvider.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
113 lines (103 loc) · 3.83 KB
Breadcrumbs
pythonVSCode
/
src
/
client
/
helpProvider.ts
Copy path
File metadata and controls
113 lines (103 loc) · 3.83 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
'use strict'
;
import
*
as
vscode
from
'vscode'
;
import
{
Disposable
}
from
'vscode'
;
import
*
as
path
from
'path'
;
import
*
as
http
from
'http'
;
import
{
createDeferred
}
from
'./common/helpers'
;
import
{
Documentation
}
from
'./common/constants'
;
const
nodeStatic
=
require
(
'node-static'
)
;
let
serverAddress
=
"http://localhost:8080"
;
let
helpPageToDisplay
=
Documentation
.
Home
;
export
class
TextDocumentContentProvider
extends
Disposable
implements
vscode
.
TextDocumentContentProvider
{
private
_onDidChange
=
new
vscode
.
EventEmitter
<
vscode
.
Uri
>
(
)
;
private
lastUri
:
vscode
.
Uri
;
constructor
(
)
{
super
(
(
)
=>
{
}
)
;
}
public
provideTextDocumentContent
(
uri
:
vscode
.
Uri
,
token
:
vscode
.
CancellationToken
)
:
Thenable
<
string
>
{
this
.
lastUri
=
uri
;
return
this
.
generateResultsView
(
)
;
}
get
onDidChange
(
)
:
vscode
.
Event
<
vscode
.
Uri
>
{
return
this
.
_onDidChange
.
event
;
}
public
update
(
)
{
this
.
_onDidChange
.
fire
(
this
.
lastUri
)
;
}
private
generateResultsView
(
)
:
Promise
<
string
>
{
const
addresss
=
serverAddress
+
helpPageToDisplay
;
const
htmlContent
=
`
<!DOCTYPE html>
<head>
<style type="text/css"> html, body{ height:100%; width:100%; }</style>
</head>
<body>
<iframe frameborder="0" style="border: 0px solid transparent;height:100%;width:100%;background-color:white;" src="
${
addresss
}
"></iframe>
</body>
</html>`
;
return
Promise
.
resolve
(
htmlContent
)
;
}
}
const
helpSchema
=
'help-viewer'
;
const
previewUri
=
vscode
.
Uri
.
parse
(
helpSchema
+
'://authority/jupyter'
)
;
export
class
HelpProvider
{
private
disposables
:
Disposable
[
]
=
[
]
;
constructor
(
)
{
const
textProvider
=
new
TextDocumentContentProvider
(
)
;
this
.
disposables
.
push
(
vscode
.
workspace
.
registerTextDocumentContentProvider
(
helpSchema
,
textProvider
)
)
;
this
.
disposables
.
push
(
vscode
.
commands
.
registerCommand
(
'python.displayHelp'
,
(
page
:
string
)
=>
{
this
.
startServer
(
)
.
then
(
port
=>
{
let
viewColumn
=
vscode
.
ViewColumn
.
Two
;
if
(
!
page
||
typeof
page
!==
'string'
||
page
.
length
===
0
)
{
helpPageToDisplay
=
Documentation
.
Home
;
viewColumn
=
vscode
.
ViewColumn
.
One
;
}
else
{
helpPageToDisplay
=
page
;
}
vscode
.
commands
.
executeCommand
(
'vscode.previewHtml'
,
previewUri
,
viewColumn
,
'Help'
)
;
}
)
;
}
)
)
;
}
dispose
(
)
{
this
.
disposables
.
forEach
(
d
=>
d
.
dispose
(
)
)
;
this
.
stop
(
)
;
}
private
httpServer
:
http
.
Server
;
private
port
:
number
;
private
startServer
(
)
:
Promise
<
number
>
{
if
(
this
.
port
)
{
return
Promise
.
resolve
(
this
.
port
)
;
}
let
def
=
createDeferred
<
number
>
(
)
;
var
file
=
new
nodeStatic
.
Server
(
path
.
join
(
__dirname
,
'..'
,
'..'
,
'docs'
)
)
;
this
.
httpServer
=
http
.
createServer
(
(
request
,
response
)
=>
{
request
.
addListener
(
'end'
,
function
(
)
{
//
// Serve files!
//
file
.
serve
(
request
,
response
)
;
}
)
.
resume
(
)
;
}
)
;
this
.
httpServer
.
listen
(
0
,
(
)
=>
{
this
.
port
=
this
.
httpServer
.
address
(
)
.
port
;
serverAddress
=
'http://localhost:'
+
this
.
port
.
toString
(
)
;
def
.
resolve
(
this
.
port
)
;
def
=
null
;
}
)
;
this
.
httpServer
.
on
(
'error'
,
error
=>
{
if
(
def
)
{
def
.
reject
(
error
)
;
def
=
null
;
}
}
)
;
return
def
.
promise
;
}
private
stop
(
)
{
if
(
!
this
.
httpServer
)
{
return
;
}
this
.
httpServer
.
close
(
)
;
this
.
httpServer
=
null
;
}
}
Back
|
FazBrowse Home
|
New Git URL