Skip to content

Commit d5c8050

Browse files
Autocomplete for globals (#300)
1 parent fc8dff5 commit d5c8050

File tree

9 files changed

+700
-6
lines changed

9 files changed

+700
-6
lines changed

packages/databricks-vscode/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"onCommand:databricks.run.runEditorContents",
5858
"onCommand:databricks.quickstart.open",
5959
"onCommand:databricks.logs.openFolder",
60+
"onCommand:databricks.autocomplete.configure",
6061
"onView:configurationView",
6162
"onView:clusterView",
6263
"onTaskType:databricks",
@@ -171,6 +172,11 @@
171172
"title": "Open full logs",
172173
"category": "Databricks"
173174
},
175+
{
176+
"command": "databricks.autocomplete.configure",
177+
"title": "Configure autocomplete for Databricks globals",
178+
"category": "Databricks"
179+
},
174180
{
175181
"command": "databricks.cluster.start",
176182
"title": "Start Cluster",
@@ -526,6 +532,9 @@
526532
}
527533
]
528534
},
535+
"extensionDependencies": [
536+
"ms-python.python"
537+
],
529538
"vsce": {
530539
"dependencies": false,
531540
"useYarn": false
Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
import typing
2+
from pyspark.sql.session import SparkSession
3+
from pyspark.sql.functions import udf as U
4+
from pyspark.sql.context import SQLContext
5+
6+
udf = U
7+
spark: SparkSession
8+
sc = spark.sparkContext
9+
sqlContext: SQLContext
10+
sql = sqlContext.sql
11+
table = sqlContext.table
12+
13+
def displayHTML(html):
14+
"""
15+
Display HTML data.
16+
17+
Parameters
18+
----------
19+
data : URL or HTML string
20+
If data is a URL, display the resource at that URL, the resource is loaded dynamically by the browser.
21+
Otherwise data should be the HTML to be displayed.
22+
23+
See also:
24+
IPython.display.HTML
25+
IPython.display.display_html
26+
"""
27+
...
28+
29+
def display(input=None, *args, **kwargs):
30+
"""
31+
Display plots or data.
32+
33+
Display plot:
34+
- display() # no-op
35+
- display(matplotlib.figure.Figure)
36+
37+
Display dataset:
38+
- display(spark.DataFrame)
39+
- display(list) # if list can be converted to DataFrame, e.g., list of named tuples
40+
- display(pandas.DataFrame)
41+
- display(koalas.DataFrame)
42+
- display(pyspark.pandas.DataFrame)
43+
44+
Display any other value that has a _repr_html_() method
45+
46+
For Spark 2.0 and 2.1:
47+
- display(DataFrame, streamName='optional', trigger=optional pyspark.sql.streaming.Trigger,
48+
checkpointLocation='optional')
49+
50+
For Spark 2.2+:
51+
- display(DataFrame, streamName='optional', trigger=optional interval like '1 second',
52+
checkpointLocation='optional')
53+
"""
54+
...
55+
56+
class dbutils:
57+
class credentials:
58+
"""
59+
Utilities for interacting with credentials within notebooks
60+
"""
61+
62+
def assumeRole(role: str) -> bool:
63+
"""
64+
Sets the role ARN to assume when looking for credentials to authenticate with S3
65+
"""
66+
...
67+
def showCurrentRole() -> typing.List[str]:
68+
"""
69+
Shows the currently set role
70+
"""
71+
...
72+
def showRoles() -> typing.List[str]:
73+
"""
74+
Shows the set of possibly assumed roles
75+
"""
76+
...
77+
78+
class data:
79+
"""
80+
Utilities for understanding and interacting with datasets (EXPERIMENTAL)
81+
"""
82+
83+
def summarize(df: any, precise: bool) -> None:
84+
"""
85+
Summarize a Spark DataFrame and visualize the statistics to get quick insights
86+
"""
87+
...
88+
89+
class fs:
90+
"""
91+
Manipulates the Databricks filesystem (DBFS) from the console
92+
"""
93+
94+
def cp(from_: str, to: str, recurse: bool = False) -> bool:
95+
"""
96+
Copies a file or directory, possibly across FileSystems
97+
"""
98+
...
99+
def head(file: str, maxBytes: int = 65536) -> str:
100+
"""
101+
Returns up to the first 'maxBytes' bytes of the given file as a String encoded in UTF-8
102+
"""
103+
...
104+
def ls(dir: str) -> typing.List[str]:
105+
"""
106+
Lists the contents of a directory
107+
"""
108+
...
109+
def mkdirs(dir: str) -> bool:
110+
"""
111+
Creates the given directory if it does not exist, also creating any necessary parent directories
112+
"""
113+
...
114+
def mv(from_: str, to: str, recurse: bool = False) -> bool:
115+
"""
116+
Moves a file or directory, possibly across FileSystems
117+
"""
118+
...
119+
def put(file: str, contents: str, overwrite: bool = False) -> bool:
120+
"""
121+
Writes the given String out to a file, encoded in UTF-8
122+
"""
123+
...
124+
def rm(dir: str, recurse: bool = False) -> bool:
125+
"""
126+
Removes a file or directory
127+
"""
128+
...
129+
def mount(
130+
source: str,
131+
mountPoint: str,
132+
encryptionType: str = "",
133+
owner: str = "",
134+
extraConfigs: typing.Map[str, str] = {},
135+
) -> bool:
136+
"""
137+
Mounts the given source directory into DBFS at the given mount point
138+
"""
139+
...
140+
def unmount(mountPoint: str) -> bool:
141+
"""
142+
Deletes a DBFS mount point
143+
"""
144+
...
145+
def updateMount(
146+
source: str,
147+
mountPoint: str,
148+
encryptionType: str = "",
149+
owner: str = "",
150+
extraConfigs: typing.Map[str, str] = {},
151+
) -> bool:
152+
"""
153+
Similar to mount(), but updates an existing mount point (if present) instead of creating a new one
154+
"""
155+
...
156+
def mounts() -> typing.List[str]:
157+
"""
158+
Displays information about what is mounted within DBFS
159+
"""
160+
...
161+
def refreshMounts() -> bool:
162+
"""
163+
Forces all machines in this cluster to refresh their mount cache, ensuring they receive the most recent information
164+
"""
165+
...
166+
167+
class jobs:
168+
"""
169+
Utilities for leveraging jobs features
170+
"""
171+
172+
class taskValues:
173+
"""
174+
Provides utilities for leveraging job task values
175+
"""
176+
177+
def get(
178+
taskKey: str, key: str, default: any = None, debugValue: any = None
179+
) -> None:
180+
"""
181+
Returns the latest task value that belongs to the current job run
182+
"""
183+
...
184+
def set(key: str, value: any) -> None:
185+
"""
186+
Sets a task value on the current task run
187+
"""
188+
...
189+
190+
class library:
191+
"""
192+
Utilities for session isolated libraries
193+
"""
194+
195+
def restartPython() -> None:
196+
"""
197+
Restart python process for the current notebook session
198+
"""
199+
...
200+
201+
class notebook:
202+
"""
203+
Utilities for the control flow of a notebook (EXPERIMENTAL)
204+
"""
205+
206+
def exit(value: str) -> None:
207+
"""
208+
This method lets you exit a notebook with a value
209+
"""
210+
...
211+
def run(path: str, timeoutSeconds: int, arguments: typing.Map[str, str]) -> str:
212+
"""
213+
This method runs a notebook and returns its exit value
214+
"""
215+
...
216+
217+
class secrets:
218+
"""
219+
Provides utilities for leveraging secrets within notebooks
220+
"""
221+
222+
def get(scope: str, key: str) -> str:
223+
"""
224+
Gets the string representation of a secret value with scope and key
225+
"""
226+
...
227+
def list(scope: str) -> typing.List[str]:
228+
"""
229+
Lists secret metadata for secrets within a scope
230+
"""
231+
...
232+
def listScopes() -> typing.List[str]:
233+
"""
234+
Lists secret scopes
235+
"""
236+
...
237+
238+
class widgets:
239+
"""
240+
provides utilities for working with notebook widgets. You can create different types of widgets and get their bound value
241+
"""
242+
243+
def get(name: str) -> str:
244+
"""Returns the current value of a widget with give name.
245+
246+
:param name: Name of the argument to be accessed
247+
:return: Current value of the widget or default value
248+
"""
249+
...
250+
def getArgument(name: str, defaultValue: typing.Optional[str] = None) -> str:
251+
"""Returns the current value of a widget with give name.
252+
253+
:param name: Name of the argument to be accessed
254+
:param defaultValue: (Deprecated) default value
255+
:return: Current value of the widget or default value
256+
"""
257+
...
258+
def text(name: str, defaultValue: str, label: str = None):
259+
"""Creates a text input widget with given name, default value and optional label for
260+
display
261+
:param name: Name of argument associated with the new input widget
262+
:param defaultValue: Default value of the input widget
263+
:param label: Optional label string for display in notebook and dashboard
264+
"""
265+
...
266+
def dropdown(
267+
name: str, defaultValue: str, choices: typing.List[str], label: str = None
268+
):
269+
"""Creates a dropdown input widget with given specification.
270+
:param name: Name of argument associated with the new input widget
271+
:param defaultValue: Default value of the input widget (must be one of choices)
272+
:param choices: List of choices for the dropdown input widget
273+
:param label: Optional label string for display in notebook and dashboard
274+
"""
275+
...
276+
def combobox(
277+
name: str,
278+
defaultValue: str,
279+
choices: typing.List[str],
280+
label: typing.Optional[str] = None,
281+
):
282+
"""Creates a combobox input widget with given specification.
283+
:param name: Name of argument associated with the new input widget
284+
:param defaultValue: Default value of the input widget
285+
:param choices: List of choices for the dropdown input widget
286+
:param label: Optional label string for display in notebook and dashboard
287+
"""
288+
...
289+
def multiselect(
290+
name: str,
291+
defaultValue: str,
292+
choices: typing.List[str],
293+
label: typing.Optional[str] = None,
294+
):
295+
"""Creates a multiselect input widget with given specification.
296+
:param name: Name of argument associated with the new input widget
297+
:param defaultValue: Default value of the input widget (must be one of choices)
298+
:param choices: List of choices for the dropdown input widget
299+
:param label: Optional label string for display in notebook and dashboard
300+
"""
301+
...
302+
def remove(name: str):
303+
"""Removes given input widget. If widget does not exist it will throw an error.
304+
:param name: Name of argument associated with input widget to be removed
305+
"""
306+
...
307+
def removeAll():
308+
"""Removes all input widgets in the notebook."""
309+
...
310+
@property
311+
def meta() -> MetaUtils:
312+
"""
313+
Methods to hook into the compiler (EXPERIMENTAL)
314+
"""
315+
...
316+
317+
getArgument = dbutils.widgets.getArgument

packages/databricks-vscode/src/extension.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {LoggerManager, Loggers} from "./logger";
1919
import {NamedLogger} from "@databricks/databricks-sdk/dist/logging";
2020
import {workspaceConfigs} from "./WorkspaceConfigs";
2121
import {PackageJsonUtils, UtilsCommands} from "./utils";
22+
import {ConfigureAutocomplete} from "./language/ConfigureAutocomplete";
2223

2324
export async function activate(
2425
context: ExtensionContext
@@ -51,6 +52,19 @@ export async function activate(
5152
metadata: await PackageJsonUtils.getMetadata(context),
5253
});
5354

55+
const configureAutocomplete = new ConfigureAutocomplete(
56+
context,
57+
workspace.workspaceFolders[0].uri.fsPath
58+
);
59+
context.subscriptions.push(
60+
configureAutocomplete,
61+
commands.registerCommand(
62+
"databricks.autocomplete.configure",
63+
configureAutocomplete.configureCommand,
64+
configureAutocomplete
65+
)
66+
);
67+
5468
context.subscriptions.push(
5569
commands.registerCommand(
5670
"databricks.logs.openFolder",

0 commit comments

Comments
 (0)