-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d28e4d
commit d0a3408
Showing
24 changed files
with
2,417 additions
and
79 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
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,8 @@ | ||
module.exports = { | ||
transform: { | ||
"^.+\\.ts?$": "ts-jest", | ||
}, | ||
testRegex: "(/__tests__/.*|\\.(test|spec))\\.[tj]sx?$", | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
testEnvironment: "node", | ||
}; |
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
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,72 @@ | ||
import { promises as fs } from "fs"; | ||
import * as vscode from "vscode"; | ||
import * as path from "path"; | ||
import * as os from "os"; | ||
import showMessage from "../preRelease/messages"; | ||
|
||
const EXTENSION_ID = "TabNine.tabnine-vscode"; | ||
const ARGV_FILE_NAME = "argv.json"; | ||
const PRODUCT_FILE_NAME = "product.json"; | ||
const PRODUCT_FILE_PATH = path.join(vscode.env.appRoot, PRODUCT_FILE_NAME); | ||
const ENABLE_PROPOSED_API = [ | ||
"", | ||
` "enable-proposed-api": ["${EXTENSION_ID}"]`, | ||
"}", | ||
]; | ||
|
||
export default async function enableProposed(): Promise<boolean> { | ||
return handleProposed().catch((error) => { | ||
console.error("failed to enable proposedAPI", error); | ||
return false; | ||
}); | ||
} | ||
|
||
async function getDataFolderName(): Promise<string | undefined> { | ||
const data = await fs.readFile(PRODUCT_FILE_PATH); | ||
const file = JSON.parse(data.toString("utf8")) as { | ||
dataFolderName?: string; | ||
}; | ||
return file?.dataFolderName; | ||
} | ||
|
||
function getArgvResource(dataFolderName: string): string { | ||
const vscodePortable = process.env.VSCODE_PORTABLE; | ||
if (vscodePortable) { | ||
return path.join(vscodePortable, ARGV_FILE_NAME); | ||
} | ||
|
||
return path.join(os.homedir(), dataFolderName, ARGV_FILE_NAME); | ||
} | ||
async function handleProposed(): Promise<boolean> { | ||
const dataFolderName = await getDataFolderName(); | ||
|
||
if (dataFolderName) { | ||
const argvResource = getArgvResource(dataFolderName); | ||
const argvString = (await fs.readFile(argvResource)).toString(); | ||
|
||
if (argvString.includes(`${EXTENSION_ID}`)) { | ||
return true; | ||
} | ||
|
||
const modifiedArgvString = modifyArgvFileContent(argvString); | ||
await fs.writeFile(argvResource, Buffer.from(modifiedArgvString)); | ||
askForReload(); | ||
} | ||
return false; | ||
} | ||
|
||
function askForReload() { | ||
void showMessage({ | ||
messageId: "inline-update", | ||
messageText: `Please reload the window for the Tabnine inline completions to take effect.`, | ||
buttonText: "Reload", | ||
action: () => | ||
void vscode.commands.executeCommand("workbench.action.reloadWindow"), | ||
}); | ||
} | ||
|
||
function modifyArgvFileContent(argvString: string) { | ||
return argvString | ||
.substring(0, argvString.length - 2) | ||
.concat(",\n", ENABLE_PROPOSED_API.join("\n")); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Disposable, TextDocumentChangeEvent, window, workspace } from "vscode"; | ||
|
||
let shouldComplete = false; | ||
let change = false; | ||
|
||
function onChange(): void { | ||
change = true; | ||
} | ||
|
||
function onTextSelectionChange(): void { | ||
if (change) { | ||
shouldComplete = true; | ||
change = false; | ||
} else { | ||
shouldComplete = false; | ||
} | ||
} | ||
export function getShouldComplete(): boolean { | ||
return shouldComplete; | ||
} | ||
|
||
export function initTracker(): Disposable[] { | ||
return [ | ||
workspace.onDidChangeTextDocument( | ||
({ contentChanges }: TextDocumentChangeEvent) => { | ||
const contentChange = contentChanges[0]; | ||
const changeHappened = | ||
contentChange?.rangeLength >= 0 && contentChange?.text !== ""; | ||
if (changeHappened) { | ||
onChange(); | ||
} | ||
} | ||
), | ||
window.onDidChangeTextEditorSelection(onTextSelectionChange), | ||
]; | ||
} |
Oops, something went wrong.