{"action":"created","issue":{"url":"https://api.github.com/repos/dsherret/ts-simple-ast/issues/326","repository_url":"https://api.github.com/repos/dsherret/ts-simple-ast","labels_url":"https://api.github.com/repos/dsherret/ts-simple-ast/issues/326/labels{/name}","comments_url":"https://api.github.com/repos/dsherret/ts-simple-ast/issues/326/comments","events_url":"https://api.github.com/repos/dsherret/ts-simple-ast/issues/326/events","html_url":"https://github.com/dsherret/ts-simple-ast/issues/326","id":322547184,"number":326,"title":"Able to create Project from existent native ts.server.Project","user":{"login":"cancerberoSgx","id":112746,"avatar_url":"https://avatars3.githubusercontent.com/u/112746?v=4","gravatar_id":"","url":"https://api.github.com/users/cancerberoSgx","html_url":"https://github.com/cancerberoSgx","followers_url":"https://api.github.com/users/cancerberoSgx/followers","following_url":"https://api.github.com/users/cancerberoSgx/following{/other_user}","gists_url":"https://api.github.com/users/cancerberoSgx/gists{/gist_id}","starred_url":"https://api.github.com/users/cancerberoSgx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cancerberoSgx/subscriptions","organizations_url":"https://api.github.com/users/cancerberoSgx/orgs","repos_url":"https://api.github.com/users/cancerberoSgx/repos","events_url":"https://api.github.com/users/cancerberoSgx/events{/privacy}","received_events_url":"https://api.github.com/users/cancerberoSgx/received_events","type":"User","site_admin":false},"labels":[{"id":552803008,"url":"https://api.github.com/repos/dsherret/ts-simple-ast/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-05-12T22:21:19Z","updated_at":"2018-05-22T11:11:35Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"It will be very common that people use this library to facilitate LanguageService plugins development. There one already have a Project instance  and since you basically are wrapping objects should be easy and straightforward to have an api to build a ts-simple-ast.Project from a ts.server.Project directly. \r\n\r\nTHis is a very very small issue, is any, actually just wanted to thank you for the project. I was doing something similar, while learning and developing my first LanguageService plugins. You solved LOTS of the problems I was envision to reach my goals. Just discovered this, thanks! :)"},"comment":{"url":"https://api.github.com/repos/dsherret/ts-simple-ast/issues/comments/390952881","html_url":"https://github.com/dsherret/ts-simple-ast/issues/326#issuecomment-390952881","issue_url":"https://api.github.com/repos/dsherret/ts-simple-ast/issues/326","id":390952881,"user":{"login":"cancerberoSgx","id":112746,"avatar_url":"https://avatars3.githubusercontent.com/u/112746?v=4","gravatar_id":"","url":"https://api.github.com/users/cancerberoSgx","html_url":"https://github.com/cancerberoSgx","followers_url":"https://api.github.com/users/cancerberoSgx/followers","following_url":"https://api.github.com/users/cancerberoSgx/following{/other_user}","gists_url":"https://api.github.com/users/cancerberoSgx/gists{/gist_id}","starred_url":"https://api.github.com/users/cancerberoSgx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cancerberoSgx/subscriptions","organizations_url":"https://api.github.com/users/cancerberoSgx/orgs","repos_url":"https://api.github.com/users/cancerberoSgx/repos","events_url":"https://api.github.com/users/cancerberoSgx/events{/privacy}","received_events_url":"https://api.github.com/users/cancerberoSgx/received_events","type":"User","site_admin":false},"created_at":"2018-05-22T11:11:35Z","updated_at":"2018-05-22T11:11:35Z","author_association":"CONTRIBUTOR","body":"Just in case I've improved the code. I find that the call always takes around 1.5 seconds no matter how big the project is. right now I'm always creating the object (each time the user actions a refactor) and I'm investigating the possibility of maintaining this object in a variable and update the source files that changed somehow before using it (or test if that is neccesary - will simple-ast project get changes made by third parties ? )\r\n\r\n```\r\nimport { basename } from 'path';\r\nimport Project from 'ts-simple-ast';\r\nimport * as ts_module from 'typescript/lib/tsserverlibrary';\r\n\r\n/** gets the config file of given ts project or undefined if given is not a ConfiguredProject or tsconfig cannot be found */\r\nfunction getConfigFilePath(project: ts_module.server.Project): string | undefined {\r\n  if ((project as ts_module.server.ConfiguredProject).getConfigFilePath) {\r\n    return (project as ts_module.server.ConfiguredProject).getConfigFilePath()\r\n  }\r\n  else {\r\n    return project.getFileNames().find(p => basename(p.toString()) === 'tsconfig.json')\r\n  }\r\n}\r\n/**\r\n * (dirty way) of creating a ts-simple-ast Project from an exiting ts.server.Project. Given project must be a\r\n * configured project (created with a tsconfig file. It will recreates the project from scratch so it can take\r\n * some time. Use it with discretion\r\n */\r\nexport function createSimpleASTProject(nativeProject: ts_module.server.Project): Project {\r\n  const tsConfigFilePath = getConfigFilePath(nativeProject)\r\n  const project = new Project({\r\n    tsConfigFilePath: getConfigFilePath(nativeProject)\r\n  })\r\n  return project\r\n}\r\n\r\n\r\n// create example: \r\nconst project = new Project({\r\n  tsConfigFilePath: getConfigFilePath(info.project)\r\n});\r\n```"}}
{"actor":{"display_login":"cancerberoSgx"}}