Skip to content

Commit

Permalink
Merge pull request #433 from CodinGame/small-files-fixes
Browse files Browse the repository at this point in the history
Small files fixes
  • Loading branch information
CGNonofr authored May 22, 2024
2 parents fafb46c + 1586b0e commit 0e4fc2a
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ await initialize({
// Open a new editor here and return it
// It will be called when for instance the user ctrl+click on an import
}),
...getConfigurationServiceOverride(vscode.Uri.file('/tmp/'))
...getConfigurationServiceOverride()
})

updateUserConfiguration(`{
Expand Down
4 changes: 2 additions & 2 deletions demo/src/features/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ void getApi().then(async debuggerVscodeApi => {
})

websocket.send(JSON.stringify({
main: '/tmp/test.js',
main: '/workspace/test.js',
files: {
'/tmp/test.js': new TextDecoder().decode(await debuggerVscodeApi.workspace.fs.readFile(debuggerVscodeApi.Uri.file('/tmp/test.js')))
'/workspace/test.js': new TextDecoder().decode(await debuggerVscodeApi.workspace.fs.readFile(debuggerVscodeApi.Uri.file('/workspace/test.js')))
}
}))

Expand Down
6 changes: 3 additions & 3 deletions demo/src/features/intellisense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void getApi().then(async api => {
return {
name: 'Fake call hierarchy',
kind: api.SymbolKind.Class,
uri: api.Uri.file('/tmp/test.js'),
uri: api.Uri.file('/workspace/test.js'),
range: new api.Range(0, 0, 0, 10),
selectionRange: new api.Range(0, 0, 0, 10)
}
Expand All @@ -32,7 +32,7 @@ void getApi().then(async api => {
from: {
name: 'Fake incomming call',
kind: api.SymbolKind.Class,
uri: api.Uri.file('/tmp/test.js'),
uri: api.Uri.file('/workspace/test.js'),
range: new api.Range(0, 0, 0, 10),
selectionRange: new api.Range(0, 0, 0, 10)
},
Expand Down Expand Up @@ -71,7 +71,7 @@ void getApi().then(async api => {
if (wordRange != null && document.getText(wordRange) === 'anotherfile') {
return {
range: wordRange,
uri: api.Uri.file('/tmp/test_readonly.js')
uri: api.Uri.file('/workspace/test_readonly.js')
}
}
return []
Expand Down
2 changes: 1 addition & 1 deletion demo/src/features/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (!useHtmlFileSystemProvider) {
fakeOutputChannel.append('Hello world\n')
}, 1000)

const mainDocument = await vscode.workspace.openTextDocument(vscode.Uri.file('/tmp/test.js'))
const mainDocument = await vscode.workspace.openTextDocument(vscode.Uri.file('/workspace/test.js'))
anotherFakeOutputChannel.replace(mainDocument.getText())
vscode.workspace.onDidChangeTextDocument((e) => {
if (e.document === mainDocument && e.contentChanges.length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/features/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ void getApi().then(async vscode => {

const group = scm.createResourceGroup('working-tree', 'Working Tree')
group.resourceStates = [{
resourceUri: vscode.Uri.file('/tmp/test.js'),
resourceUri: vscode.Uri.file('/workspace/test.js'),
command: {
title: 'Commit',
command: 'scm-demo.click-file',
arguments: [vscode.Uri.file('/tmp/test.js')]
arguments: [vscode.Uri.file('/workspace/test.js')]
}
}, {
resourceUri: vscode.Uri.file('/tmp/test_readonly.js'),
resourceUri: vscode.Uri.file('/workspace/test_readonly.js'),
command: {
title: 'Commit',
command: 'scm-demo.click-file',
arguments: [vscode.Uri.file('/tmp/test_readonly.js')]
arguments: [vscode.Uri.file('/workspace/test_readonly.js')]
},
decorations: {
strikeThrough: true,
Expand Down
2 changes: 1 addition & 1 deletion demo/src/features/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ export class TerminalBackend extends SimpleTerminalBackend {
override clearBuffer (): void | Promise<void> {
}
}
return new FakeTerminalProcess(1, 1, '/tmp', dataEmitter.event)
return new FakeTerminalProcess(1, 1, '/workspace', dataEmitter.event)
}
}
4 changes: 2 additions & 2 deletions demo/src/main.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ const { getApi } = registerExtension({

void getApi().then(async vscode => {
if (!useHtmlFileSystemProvider) {
const mainModelUri = vscode.Uri.file('/tmp/test.js')
const mainModelUri = vscode.Uri.file('/workspace/test.js')
await Promise.all([
vscode.workspace.openTextDocument(mainModelUri),
vscode.workspace.openTextDocument(monaco.Uri.file('/tmp/test_readonly.js')) // open the file so vscode sees it's locked
vscode.workspace.openTextDocument(monaco.Uri.file('/workspace/test_readonly.js')) // open the file so vscode sees it's locked
])

const diagnostics = vscode.languages.createDiagnosticCollection('demo')
Expand Down
22 changes: 11 additions & 11 deletions demo/src/setup.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if (useHtmlFileSystemProvider) {
} else {
const fileSystemProvider = new RegisteredFileSystemProvider(false)

fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/test.js'), `// import anotherfile
fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/workspace/test.js'), `// import anotherfile
let variable = 1
function inc () {
variable++
Expand All @@ -103,9 +103,9 @@ while (variable < 5000) {
}`
))

fileSystemProvider.registerFile(new RegisteredReadOnlyFile(vscode.Uri.file('/tmp/test_readonly.js'), async () => 'This is a readonly static file'))
fileSystemProvider.registerFile(new RegisteredReadOnlyFile(vscode.Uri.file('/workspace/test_readonly.js'), async () => 'This is a readonly static file'))

fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/jsconfig.json'), `{
fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/workspace/jsconfig.json'), `{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
Expand All @@ -117,7 +117,7 @@ while (variable < 5000) {
}`
))

fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/index.html'), `
fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/workspace/index.html'), `
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -137,7 +137,7 @@ while (variable < 5000) {
</html>`
))

fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/test.md'), `
fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/workspace/test.md'), `
***Hello World***
Math block:
Expand All @@ -160,11 +160,11 @@ $$
`
))

fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/test.customeditor'), `
fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/workspace/test.customeditor'), `
Custom Editor!`
))

fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/tmp/test.css'), `
fileSystemProvider.registerFile(new RegisteredMemoryFile(vscode.Uri.file('/workspace/test.css'), `
h1 {
color: DeepSkyBlue;
}`
Expand All @@ -173,11 +173,11 @@ h1 {
// Use a workspace file to be able to add another folder later (for the "Attach filesystem" button)
fileSystemProvider.registerFile(new RegisteredMemoryFile(workspaceFile, JSON.stringify(<IStoredWorkspace>{
folders: [{
path: '/tmp'
path: '/workspace'
}]
}, null, 2)))

fileSystemProvider.registerFile(new RegisteredMemoryFile(monaco.Uri.file('/tmp/.vscode/extensions.json'), JSON.stringify({
fileSystemProvider.registerFile(new RegisteredMemoryFile(monaco.Uri.file('/workspace/.vscode/extensions.json'), JSON.stringify({
recommendations: [
'vscodevim.vim'
]
Expand Down Expand Up @@ -246,10 +246,10 @@ export const constructOptions: IWorkbenchConstructionOptions = {
editors: useHtmlFileSystemProvider
? undefined
: [{
uri: monaco.Uri.file('/tmp/test.js'),
uri: monaco.Uri.file('/workspace/test.js'),
viewColumn: 1
}, {
uri: monaco.Uri.file('/tmp/test.md'),
uri: monaco.Uri.file('/workspace/test.md'),
viewColumn: 2
}],
layout: useHtmlFileSystemProvider
Expand Down
11 changes: 9 additions & 2 deletions src/service-override/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ class RegisteredMemoryFile extends RegisteredFile {
}
}

function addTrailingSlash (uri: string) {
if (!uri.endsWith('/')) {
return uri + '/'
}
return uri
}

const encoder = new TextEncoder()
const decoder = new TextDecoder()
class RegisteredFileSystemProvider extends Disposable implements IFileSystemProviderWithFileReadWriteCapability {
Expand Down Expand Up @@ -183,7 +190,7 @@ class RegisteredFileSystemProvider extends Disposable implements IFileSystemProv
}
const handledUris = Array.from(this.files.keys())
for (const handledUri of handledUris) {
if (handledUri.startsWith(resourceUri + '/')) {
if (handledUri.startsWith(addTrailingSlash(resourceUri))) {
return {
ctime: Date.now(),
mtime: Date.now(),
Expand All @@ -199,7 +206,7 @@ class RegisteredFileSystemProvider extends Disposable implements IFileSystemProv
public async readdir (resource: URI): Promise<[string, FileType][]> {
const includedPaths = Array.from(this.files.keys())
.map(uri => URI.parse(uri))
.filter(uri => uri.authority === resource.authority && uri.path.startsWith(resource.path + '/'))
.filter(uri => uri.authority === resource.authority && uri.path.startsWith(addTrailingSlash(resource.path)))
.map(uri => extUri.relativePath(resource, uri)!)

const files = includedPaths.filter(path => !path.includes('/'))
Expand Down

1 comment on commit 0e4fc2a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.