forked from facebookarchive/nuclide
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a nuclide-swift package. nuclide-swift registers a toolbar that invokes Swift package manager commands such as `swift build` and `swift test`. This package makes use of SwiftPM to also provide precise compilation flags to SourceKitten, which allows Nuclide to provide detailed type information.
- Loading branch information
Showing
16 changed files
with
642 additions
and
4 deletions.
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,5 @@ | ||
{ | ||
"atom-workspace": { | ||
"ctrl-cmd-p": "nuclide-swift:create-new-package" | ||
} | ||
} |
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,47 @@ | ||
'use babel'; | ||
/* @flow */ | ||
|
||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the LICENSE file in | ||
* the root directory of this source tree. | ||
*/ | ||
|
||
import {asyncExecute} from '../../commons-node/process'; | ||
import {trackTiming} from '../../nuclide-analytics'; | ||
import {getLogger} from '../../nuclide-logging'; | ||
import fsPromise from '../../commons-node/fsPromise'; | ||
|
||
|
||
export default class CodeFormatHelpers { | ||
@trackTiming('nuclide-swift.formatCode') | ||
static async formatEntireFile(editor: atom$TextEditor, range: atom$Range): Promise<{ | ||
newCursor?: number; | ||
formatted: string; | ||
}> { | ||
const tempFile = await fsPromise.tempfile(); | ||
try { | ||
const beforeFile = editor.getBuffer().getText(); | ||
await fsPromise.writeFile(tempFile, beforeFile); | ||
|
||
const result = await asyncExecute( | ||
'sourcekitten', | ||
['format', '--file', tempFile], | ||
{} | ||
); | ||
const afterFile = await fsPromise.readFile(tempFile, 'utf8'); | ||
|
||
return { | ||
newCursor: null, | ||
formatted: afterFile, | ||
}; | ||
} catch (e) { | ||
getLogger().error('Could not run `sourcekitten format`', e); | ||
throw new Error('Could not run `sourcekitten format`.<br>Ensure it is installed and in your $PATH.'); | ||
} finally { | ||
await fsPromise.unlink(tempFile); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use babel'; | ||
/* @flow */ | ||
|
||
/* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the license found in the LICENSE file in | ||
* the root directory of this source tree. | ||
*/ | ||
|
||
import type {Outline, OutlineTree} from '../../../nuclide-outline-view'; | ||
|
||
import {Point} from 'atom'; | ||
import {asyncExecute} from '../../../commons-node/process'; | ||
import {arrayCompact} from '../../../commons-node/collection'; | ||
|
||
export async function getOutline(editor: atom$TextEditor): Promise<?Outline> { | ||
const contents = editor.getText(); | ||
const result = await asyncExecute( | ||
// TODO use the setting for sourcekitten path | ||
'sourcekitten', | ||
[ | ||
'structure', | ||
'--text', contents, | ||
// TODO add compiler args? | ||
], | ||
); | ||
|
||
// TODO handle errors | ||
return outputToOutline(result.stdout); | ||
} | ||
|
||
function outputToOutline(output: string): Outline { | ||
const json = JSON.parse(output); | ||
|
||
const outlineTrees: Array<?OutlineTree> = json['key.substructure'].map(itemToOutline); | ||
return { | ||
outlineTrees: arrayCompact(outlineTrees), | ||
}; | ||
} | ||
|
||
function itemToOutline(item: Object): ?OutlineTree { | ||
// TODO support more things | ||
switch (item['key.kind']) { | ||
case 'source.lang.swift.decl.var.global': | ||
return { | ||
plainText: item['key.name'], | ||
// TODO get the actual start position | ||
startPosition: new Point(0, 0), | ||
children: [], | ||
}; | ||
default: | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.