Skip to content

Commit 6208b4c

Browse files
Move autcompletion for globals to __builtins__.py from internal stubs. (#675)
## Changes We are deprecating internal type stubs in favour of python sdk. Python sdk currently only provides typings for dbutils. This adds typings for other globals to `__builtins__.py`. **Removed docstrings** for these globals since they were 10+ lines each, adding a big chunk to the user's builtins file. * displayHTML() * display
1 parent b7c0138 commit 6208b4c

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from databricks.sdk.runtime import *
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+
getArgument = dbutils.widgets.getArgument
13+
14+
def displayHTML(html): ...
15+
16+
def display(input=None, *args, **kwargs): ...

packages/databricks-vscode/src/language/ConfigureAutocomplete.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@ import {WorkspaceStateManager} from "../vscode-objs/WorkspaceState";
1313
import {MsPythonExtensionWrapper} from "./MsPythonExtensionWrapper";
1414
import {DbConnectInstallPrompt} from "./DbConnectInstallPrompt";
1515

16-
const importString = "from databricks.sdk.runtime import *";
16+
async function getImportString(context: ExtensionContext) {
17+
try {
18+
return await readFile(
19+
context.asAbsolutePath(
20+
path.join("resources", "stubs", "__builtins__.pyi")
21+
),
22+
"utf-8"
23+
);
24+
} catch (e: unknown) {
25+
if (e instanceof Error) {
26+
window.showErrorMessage(
27+
`Can't read internal type stubs for autocompletion. ${e.message}`
28+
);
29+
}
30+
}
31+
}
1732

18-
type StepResult = "Skip" | "Cancel" | "Error" | "Silent" | undefined;
33+
type StepResult = "Skip" | "Cancel" | "Error" | undefined;
1934

2035
interface Step {
2136
fn: (dryRun: boolean) => Promise<StepResult>;
@@ -170,6 +185,11 @@ export class ConfigureAutocomplete implements Disposable {
170185

171186
const builtinsPath = path.join(builtinsDir, "__builtins__.pyi");
172187

188+
const importString = await getImportString(this.context);
189+
if (importString === undefined) {
190+
return "Error";
191+
}
192+
173193
if (
174194
builtinsFileExists &&
175195
(await readFile(builtinsPath, "utf-8")).includes(importString)

0 commit comments

Comments
 (0)