-
Notifications
You must be signed in to change notification settings - Fork 11
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
Adds formatting capabilities to vs-code extension #402
Merged
simonthuresson
merged 13 commits into
neo4j:main
from
simonthuresson:vs-code-formatterv2
Mar 12, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3f7699a
can change document
simonthuresson 04d0cb4
refactores format document
simonthuresson 69eced7
uses non deprecated type
simonthuresson 6cfe084
changed import order back to original
simonthuresson c7f9a3e
updates readme for vs-code extension
simonthuresson 8f15e30
Updates changelog
simonthuresson a112798
bumps vs-code extension version
simonthuresson f5553ac
Removes reordering of ON CREATE/MATCH clauses in formatter (#399)
tomasnyberg de01d1f
Fixes IS CONNECTED concatenate bug in formatter (#401)
tomasnyberg a2d7973
adds e2e tests for extension
simonthuresson b3cae14
modified test
simonthuresson 0e869d9
Merge branch 'main' into vs-code-formatterv2
simonthuresson 456f1bb
deletes unused file
simonthuresson 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { formatQuery } from '@neo4j-cypher/language-support'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import { | ||
DocumentFormattingParams, | ||
TextDocuments, | ||
TextEdit, | ||
} from 'vscode-languageserver/node'; | ||
|
||
export const formatDocument = ( | ||
params: DocumentFormattingParams, | ||
documents: TextDocuments<TextDocument>, | ||
): TextEdit[] => { | ||
const document = documents.get(params.textDocument.uri); | ||
if (!document) { | ||
return []; | ||
} | ||
|
||
const text = document.getText(); | ||
const formattedText = formatQuery(text); | ||
|
||
if (text === formattedText) { | ||
return []; | ||
} | ||
|
||
return [ | ||
TextEdit.replace( | ||
{ | ||
start: { line: 0, character: 0 }, | ||
end: { line: document.lineCount, character: 0 }, | ||
}, | ||
formattedText, | ||
), | ||
]; | ||
}; |
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
17 changes: 17 additions & 0 deletions
17
packages/vscode-extension/tests/specs/api/formatting.spec.ts
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as assert from 'assert'; | ||
import * as vscode from 'vscode'; | ||
import { newUntitledFileWithContent } from '../../helpers'; | ||
|
||
suite('Formatting', () => { | ||
test('tests that formatting document works', async () => { | ||
const query = `match (p: Person) where p.name = "John Doe" reTUrn p lIMIt 25`; | ||
const document = await newUntitledFileWithContent(query); | ||
await vscode.commands.executeCommand('editor.action.formatDocument'); | ||
const formattedText = document.getText(); | ||
const expected = `MATCH (p:Person) | ||
WHERE p.name = "John Doe" | ||
RETURN p | ||
LIMIT 25`; | ||
assert.equal(formattedText, expected); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -69,7 +69,7 @@ export async function testSyntaxValidation({ | |
); | ||
} | ||
|
||
suite.only('Syntax validation spec', () => { | ||
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. 👍 |
||
suite('Syntax validation spec', () => { | ||
afterEach(async () => { | ||
await toggleLinting(true); | ||
}); | ||
|
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.
🎉