Skip to content

Commit f4f8bbb

Browse files
committed
fix: add some debugging output
1 parent 04359f1 commit f4f8bbb

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

src/extension.ts

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ interface TextSnippet {
1212
}
1313

1414
export function activate(context: vscode.ExtensionContext): void {
15+
const output = vscode.window.createOutputChannel('Material-UI Snippets')
16+
output.appendLine('Available snippets:')
17+
for (const snippet of Object.values(snippets)) {
18+
output.appendLine(` ${snippet.prefix}`)
19+
}
20+
1521
for (const language of ['javascriptreact', 'typescriptreact']) {
1622
let lastOptions: SnippetOptions | null = null
1723
let lastSnippets: TextSnippet[]
@@ -50,44 +56,52 @@ export function activate(context: vscode.ExtensionContext): void {
5056
): vscode.ProviderResult<
5157
vscode.CompletionItem[] | vscode.CompletionList
5258
> {
53-
let insertPosition: vscode.Position = new vscode.Position(0, 0)
54-
let existingImports: Set<string> | null
59+
output.appendLine('provideCompletionItems() called')
5560
try {
56-
;({ insertPosition, existingImports } = getExistingImports(
57-
document
58-
))
61+
let insertPosition: vscode.Position = new vscode.Position(0, 0)
62+
let existingImports: Set<string> | null
63+
try {
64+
;({ insertPosition, existingImports } = getExistingImports(
65+
document
66+
))
67+
} catch (error) {
68+
existingImports = null
69+
}
70+
const result = []
71+
for (const snippet of getSnippets({
72+
language: language as any, // eslint-disable-line @typescript-eslint/no-explicit-any
73+
formControlMode:
74+
vscode.workspace
75+
.getConfiguration('material-ui-snippets')
76+
.get('formControlMode') || 'controlled',
77+
})) {
78+
const { prefix, description, body, imports } = snippet
79+
const snippetCompletion = new vscode.CompletionItem(prefix)
80+
snippetCompletion.insertText = new vscode.SnippetString(body)
81+
snippetCompletion.documentation = new vscode.MarkdownString(
82+
description
83+
)
84+
const finalExistingImports = existingImports
85+
if (finalExistingImports) {
86+
snippetCompletion.additionalTextEdits = [
87+
vscode.TextEdit.insert(
88+
insertPosition,
89+
[...Object.entries(imports)]
90+
.filter(([source]) => !finalExistingImports.has(source))
91+
.map(entry => entry[1])
92+
.join('\n') + '\n'
93+
),
94+
]
95+
}
96+
result.push(snippetCompletion)
97+
}
98+
output.appendLine('provideCompletionItems() returning')
99+
return result
59100
} catch (error) {
60-
existingImports = null
61-
}
62-
const result = []
63-
for (const snippet of getSnippets({
64-
language: language as any, // eslint-disable-line @typescript-eslint/no-explicit-any
65-
formControlMode:
66-
vscode.workspace
67-
.getConfiguration('material-ui-snippets')
68-
.get('formControlMode') || 'controlled',
69-
})) {
70-
const { prefix, description, body, imports } = snippet
71-
const snippetCompletion = new vscode.CompletionItem(prefix)
72-
snippetCompletion.insertText = new vscode.SnippetString(body)
73-
snippetCompletion.documentation = new vscode.MarkdownString(
74-
description
101+
output.appendLine(
102+
'provideCompletionItems() ERROR: ' + error.message
75103
)
76-
const finalExistingImports = existingImports
77-
if (finalExistingImports) {
78-
snippetCompletion.additionalTextEdits = [
79-
vscode.TextEdit.insert(
80-
insertPosition,
81-
[...Object.entries(imports)]
82-
.filter(([source]) => !finalExistingImports.has(source))
83-
.map(entry => entry[1])
84-
.join('\n') + '\n'
85-
),
86-
]
87-
}
88-
result.push(snippetCompletion)
89104
}
90-
return result
91105
},
92106
})
93107
)

0 commit comments

Comments
 (0)