Skip to content

Commit

Permalink
chore(activateLsp): add onDidChangeConfiguration to disposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 authored and HerringtonDarkholme committed Feb 7, 2024
1 parent 9953359 commit 521ea74
Showing 1 changed file with 59 additions and 57 deletions.
116 changes: 59 additions & 57 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,61 +154,70 @@ interface ScanResult {
}

function activateLsp(context: ExtensionContext) {
let disposable = commands.registerCommand('ast-grep.search', async _uri => {
let curWorkspace = workspace.workspaceFolders?.[0]
if (!curWorkspace) {
return
}
const referenceView = await extensions
.getExtension('vscode.references-view')
?.activate()
let pattern
try {
pattern = await window.showInputBox({})
} catch {
return
}
if (!pattern) {
return
}
let res = await client.sendRequest<ScanResult[]>('ast-grep/search', {
pattern: pattern
})
context.subscriptions.push(
commands.registerCommand('ast-grep.search', async _uri => {
let curWorkspace = workspace.workspaceFolders?.[0]
if (!curWorkspace) {
return
}
const referenceView = await extensions
.getExtension('vscode.references-view')
?.activate()
let pattern
try {
pattern = await window.showInputBox({})
} catch {
return
}
if (!pattern) {
return
}
let res = await client.sendRequest<ScanResult[]>('ast-grep/search', {
pattern: pattern
})

let treeItemList: AstGrepScanTreeItem[] = []
let grouped = groupBy(res, 'uri')
for (let uri of Object.keys(grouped)) {
let scanResultList = grouped[uri]
for (let element of scanResultList) {
treeItemList.push(
new AstGrepScanTreeItem({
source: element.content,
range: element.position,
uri: element.uri
})
)
let treeItemList: AstGrepScanTreeItem[] = []
let grouped = groupBy(res, 'uri')
for (let uri of Object.keys(grouped)) {
let scanResultList = grouped[uri]
for (let element of scanResultList) {
treeItemList.push(
new AstGrepScanTreeItem({
source: element.content,
range: element.position,
uri: element.uri
})
)
}
}
}
let provider = new NodeDependenciesProvider(grouped)
let provider = new NodeDependenciesProvider(grouped)

let symbolTreeInput = {
contextValue: 'ast-grep',
title: 'ast-grep',
location: {
uri: window.activeTextEditor?.document.uri,
range: new Range(new Position(0, 0), new Position(0, 0))
},
resolve() {
return provider
},
with() {
return symbolTreeInput
let symbolTreeInput = {
contextValue: 'ast-grep',
title: 'ast-grep',
location: {
uri: window.activeTextEditor?.document.uri,
range: new Range(new Position(0, 0), new Position(0, 0))
},
resolve() {
return provider
},
with() {
return symbolTreeInput
}
}
}
referenceView.setInput(symbolTreeInput)
})
referenceView.setInput(symbolTreeInput)
})
)

context.subscriptions.push(disposable)
context.subscriptions.push(
workspace.onDidChangeConfiguration(changeEvent => {
if (changeEvent.affectsConfiguration('astGrep')) {
deactivate()
client.start()
}
})
)

// instantiate and set input which updates the view
// If the extension is launched in debug mode then the debug server options are used
Expand Down Expand Up @@ -331,13 +340,6 @@ async function restart() {
return await client.start()
}

workspace.onDidChangeConfiguration(changeEvent => {
if (changeEvent.affectsConfiguration('astGrep')) {
deactivate()
client.start()
}
})

export function deactivate(): Promise<void> | undefined {
if (!client) {
return undefined
Expand Down

0 comments on commit 521ea74

Please sign in to comment.