-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement file index provider #98
Open
benesch
wants to merge
1
commit into
SchoofsKelvin:master
Choose a base branch
from
benesch:file-index
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,30 @@ import * as path from 'path'; | |
import * as ssh2 from 'ssh2'; | ||
import * as ssh2s from 'ssh2-streams'; | ||
import * as vscode from 'vscode'; | ||
import * as split from 'binary-split'; | ||
import { FileSystemConfig } from './manager'; | ||
|
||
export class SSHFileSystem implements vscode.FileSystemProvider { | ||
export class SSHFileSystem implements vscode.FileSystemProvider, vscode.FileIndexProvider { | ||
public waitForContinue = false; | ||
public closed = false; | ||
public closing = false; | ||
public copy = undefined; | ||
public onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]>; | ||
protected onDidChangeFileEmitter = new vscode.EventEmitter<vscode.FileChangeEvent[]>(); | ||
|
||
constructor(public readonly authority: string, protected sftp: ssh2.SFTPWrapper, | ||
public readonly root: string, public readonly config: FileSystemConfig) { | ||
constructor( | ||
public readonly authority: string, | ||
protected ssh: ssh2.Client, | ||
protected sftp: ssh2.SFTPWrapper, | ||
public readonly root: string, | ||
public readonly config: FileSystemConfig) { | ||
this.onDidChangeFile = this.onDidChangeFileEmitter.event; | ||
this.sftp.on('end', () => this.closed = true); | ||
this.ssh.on('end', () => this.closed = true); | ||
} | ||
|
||
public disconnect() { | ||
this.closing = true; | ||
this.sftp.end(); | ||
this.ssh.end(); | ||
} | ||
|
||
public relative(relPath: string) { | ||
|
@@ -138,6 +143,39 @@ export class SSHFileSystem implements vscode.FileSystemProvider { | |
public rename(oldUri: vscode.Uri, newUri: vscode.Uri, options: { overwrite: boolean; }): void | Promise<void> { | ||
return this.continuePromise(cb => this.sftp.rename(this.relative(oldUri.path), this.relative(newUri.path), cb)); | ||
} | ||
|
||
public async provideFileIndex(options: vscode.FileSearchOptions, token: vscode.CancellationToken): Promise<vscode.Uri[]> { | ||
const name = this.config.label || this.config.name; | ||
const command = `find ${this.relative(options.folder.path)} -print0`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you checked whether this command and syntax is available on all distros that support SFTP? |
||
return new Promise<vscode.Uri[]>((resolve, reject) => { | ||
const stream = this.ssh.exec(command, (err, stream) => { | ||
if (err) return reject(err); | ||
stream.stderr.on('data', (d) => { | ||
console.log("Stderr from directory listing:", d.toString()) | ||
}) | ||
const uris: vscode.Uri[] = []; | ||
stream.pipe(split("\x00")).on('data', (d) => { | ||
const p = path.posix.relative(this.root, d.toString()); | ||
uris.push(vscode.Uri.parse(`ssh://${name}/${p}`)) | ||
}); | ||
stream.on('error', reject); | ||
stream.on('close', (exitCode, signal) => { | ||
if (exitCode || signal) { | ||
return reject(new Error("error listing directory")); | ||
} | ||
resolve(uris); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
public async provideTextSearchResults( | ||
query: vscode.TextSearchQuery, | ||
options: vscode.TextSearchOptions, | ||
progress: vscode.Progress<vscode.TextSearchResult>, token: vscode.CancellationToken | ||
): Promise<void> { | ||
|
||
} | ||
} | ||
|
||
export default SSHFileSystem; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't thought of using this variable, but it's a good idea. If you want, you can make this a separate PR, or let me commit it myself.